Re: need help about code mobility

Brian Pontarelli <[email protected]>
Newsgroups gmane.comp.java.sun.jini
Message-ID <[email protected]>
Niclas Hedhman wrote:
> On Friday 29 December 2006 11:38, Brian Pontarelli wrote:
>
>> I highly doubt this was arrogance. More than likely a language
>> barrier issue.
>>
>
> Point taken. Still, general advice to everyone: If you want help, listen to
> what the helper is asking for.
>
Agreed. And I think as the mail lists move over a set of guidelines will
probably be setup as part of the Apache process. This will help in
guiding newer users, but there will still be a lot of users who don't
read them, so be prepared.


>> BTW loadClass can eventually call defineClass, which can throw a
>> NoClassDefFoundError. I didn't test but if I recall correctly this happens
>> during linkage to parents, interfaces, etc.
>>
>
> Correct, NCDFE happens when the loaded(!) class is being resolved (afaik not
> during defineClass), i.e. the referred classes are linked and possibly
> loaded.
>
> But, cl.loadClass( "B" ) will not generate "NCDFE: class B".
>
It occurs in the defineClass and not in the loadClass. What happens is
that if the class being requested can be loaded but something it extends
can't, you get the NCDFE. The reason is that the extended class is
linked to in defineClass. Here is an example stack trace that
illustrates this:

Exception in thread "main" java.lang.NoClassDefFoundError: A
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
        at
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
        at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)


Here is the code:

public class A {
}

public class B extends A {
}


Here is the command line:

rm A.class; java -cp . B


What happens this:

1. B is loaded
2. B is defined (i.e. all of its parents and interfaces are resolved and
loaded) and everything is linked together.

Since A.class is not in the classpath (since I removed it prior to
running B), during linkage of B in step 2 a NCDFE is thrown.

-bp

--------------------------------------------------------------------------
Getting Started:     http://www.jini.org/wiki/Category:Getting_Started
Community Web Site:  http://jini.org
jini-users Archive:  http://archives.java.sun.com/archives/jini-users.html
Unsubscribing:       email "signoff JINI-USERS"  to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.