This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
"Warning! Cannot create instance of desired class." is the message I get when I try to customize a serialized bean. What I have done to see this message box: + Installed NB 3.3.1 (also 3.3.1-CVS is it named "current"?). + Compiled the "examples". // Everything compiles. + Right-clicked the "advanced/MemoryView" form node. + Selected "Customize bean" // The MemoryView form opens. + Clicked the "Serialize as..." button and set the location to default sample directory. + Entered as a bean name "MyMemoryView" (...) pressed OK + Double clicked the "MyMemoryView" node // "Warning! Cannot ..." I will append the stack trace from this warning. (If I find the "attach" button) Next try was to create a non-gui bean. So I used the "New"-"Bean" wizard and saved/compiled the source file in the default "sampledir". Same procedure as above. Same result. If the stack trace differs, I'll post it to.
Created attachment 4876 [details] "MyMemoryView" log output
This part of code is located in OpenIDE part. Not beans module job.
Tried to switch from JDK 1.4 back to JDK 1.3.1 but that did not help.
I think the problem is in that InstanceSupport.instanceCreate uses NbObjectInputStream for desrialization which uses systemClassLoader (and not currentClassLoader)...
I see two possible fixes - as I'm still not too deep in the sources, I might propose the wrong solutions. Anyway, here they are: 1. Use another ObjectInputStream implementation, that utilizes the currentClassLoader or 2. make NbObjectInputStream use the currentClassLoader.
[org.openide.util.io.NbObjectInputStream:67] private static ClassLoader getNBClassLoader() { /**/ClassLoader c = (ClassLoader)Lookup.getDefault ().lookup (ClassLoader.class); return c != null ? c : ClassLoader.getSystemClassLoader (); } Should the first line return the currentClassLoader? Or in other words, how to lookup the currentClassLoader?
Forcing the above method "getNBClassLoader()" to... { return TopManager.getDefault().currentClassLoader(); } ...fixes the bug. Does it break anything?
Created attachment 4921 [details] Inner-class-specialized-OIS-patch-proposal
This patch is just a "higher-level" solution to the May be it is way of cleaner to create a new file that contains a class extending "NbObjectInputStream".
Was suggested on dev@openide that the bug is in clazz module for using InstanceSupport for user *.ser (and *.class) files. Or if it uses InstanceSupport, it should use a subclass which selects currentClassLoader. NbObjectInputStream must not refer to TopManager because of API separation.
I think that the patch of InstanceSupport is fine. Should we move the issue to openide/datasystems?
It is not fine, it is a workaround. When I was suggesting that solution, I was talking about choosing CL by the domain the serialized file came from. If I have a serialized file in my system userdir (say a compiler), I really don't like the IDE loading *repository* classes when I hit <Compile>. The problem should be either fixed in clazz module or the patch need to be enhanced to do source domain checking and providing proper CL for each domain.
I will try to fix it in Clazz module.
Fixed in clazz module. Deseralization uses currentClassLoader.
VERIFIED
Resolved for 3.3.x or earlier, no new info since then -> closing.