logo       

Patch: RFC: ClassLoader and resolution: msg#00169

java.classpath.patches

Subject: Patch: RFC: ClassLoader and resolution

I wanted to post this for comment. I couldn't easily test this inside
libgcj, due to an oddity of our implementation. (I'll send a note
about that too, shortly.)

It seems to me that if you call loadClass("foo",false) and then
loadClass("foo",true), the second call will not actually resolve the
class, due to the early return in ClassLoader.loadClass(). This patch
fixes the apparent bug.

This patch is smaller than it looks, really it is mostly removing the
early return and wrapping most of the body of the method in an 'if'.

Any comments?

Tom

Index: ChangeLog
from Tom Tromey <tromey@xxxxxxxxxx>

* java/lang/ClassLoader.java (loadClass): Resolve class even if
it was already found.

Index: java/lang/ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.47
diff -u -r1.47 ClassLoader.java
--- java/lang/ClassLoader.java 16 Feb 2005 11:18:37 -0000 1.47
+++ java/lang/ClassLoader.java 23 Mar 2005 20:09:43 -0000
@@ -321,28 +321,28 @@
{
// Have we already loaded this class?
Class c = findLoadedClass(name);
- if (c != null)
- return c;
-
- // Can the class be loaded by a parent?
- try
+ if (c == null)
{
- if (parent == null)
+ // Can the class be loaded by a parent?
+ try
{
- c = VMClassLoader.loadClass(name, resolve);
- if (c != null)
- return c;
+ if (parent == null)
+ {
+ c = VMClassLoader.loadClass(name, resolve);
+ if (c != null)
+ return c;
+ }
+ else
+ {
+ return parent.loadClass(name, resolve);
+ }
}
- else
+ catch (ClassNotFoundException e)
{
- return parent.loadClass(name, resolve);
}
+ // Still not found, we have to do it ourself.
+ c = findClass(name);
}
- catch (ClassNotFoundException e)
- {
- }
- // Still not found, we have to do it ourself.
- c = findClass(name);
if (resolve)
resolveClass(c);
return c;


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise