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.

Bug 21028 - Cannot create instance of desired class.
Summary: Cannot create instance of desired class.
Status: CLOSED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Unsupported (show other bugs)
Version: 3.x
Hardware: PC Windows ME/2000
: P3 blocker (vote)
Assignee: Tomas Hurka
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-02-28 22:22 UTC by _ sormuras
Modified: 2003-06-30 16:43 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
"MyMemoryView" log output (2.21 KB, text/plain)
2002-02-28 22:31 UTC, _ sormuras
Details
Inner-class-specialized-OIS-patch-proposal (1.61 KB, patch)
2002-03-04 13:01 UTC, _ sormuras
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description _ sormuras 2002-02-28 22:22:38 UTC
"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.
Comment 1 _ sormuras 2002-02-28 22:31:14 UTC
Created attachment 4876 [details]
"MyMemoryView" log output
Comment 2 Petr Suchomel 2002-03-01 08:20:11 UTC
This part of code is located in OpenIDE part. Not beans module job.
Comment 3 _ sormuras 2002-03-01 13:27:13 UTC
Tried to switch from JDK 1.4 back to JDK 1.3.1 but that did not help.
Comment 4 Tomas Pavek 2002-03-04 09:54:56 UTC
I think the problem is in that InstanceSupport.instanceCreate uses 
NbObjectInputStream for desrialization which uses systemClassLoader 
(and not currentClassLoader)...
Comment 5 _ sormuras 2002-03-04 10:10:37 UTC
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.
Comment 6 _ sormuras 2002-03-04 10:45:21 UTC
[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?
Comment 7 _ sormuras 2002-03-04 11:45:56 UTC
Forcing the above method "getNBClassLoader()" to... {
  return 
TopManager.getDefault().currentClassLoader();
}

...fixes the bug. Does 
it break anything?
Comment 8 _ sormuras 2002-03-04 13:01:55 UTC
Created attachment 4921 [details]
Inner-class-specialized-OIS-patch-proposal
Comment 9 _ sormuras 2002-03-04 13:29:55 UTC
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".
Comment 10 Jesse Glick 2002-03-04 20:16:58 UTC
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.
Comment 11 Jaroslav Tulach 2002-03-05 06:26:04 UTC
I think that the patch of InstanceSupport is fine. Should we move the
issue to openide/datasystems?
Comment 12 Petr Nejedly 2002-03-05 08:07:42 UTC
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.
Comment 13 Tomas Hurka 2002-03-06 12:33:38 UTC
I will try to fix it in Clazz module.
Comment 14 Tomas Hurka 2002-03-11 18:00:24 UTC
Fixed in clazz module. Deseralization uses currentClassLoader. 
Comment 15 Jan Becicka 2002-06-27 12:36:49 UTC
VERIFIED
Comment 16 Quality Engineering 2003-06-30 16:43:56 UTC
Resolved for 3.3.x or earlier, no new info since then -> closing.