Skip to content

Commit 6e8a97d

Browse files
committedSep 25, 2019
Issue janino-compiler#104: ClassLoaderIClassLoader 's ClassNotFoundException handle mechanism enhancement
1 parent 5ec8bb0 commit 6e8a97d

File tree

1 file changed

+11
-18
lines changed

1 file changed

+11
-18
lines changed
 

‎janino/src/main/java/org/codehaus/janino/ClassLoaderIClassLoader.java

+11-18
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,21 @@ class ClassLoaderIClassLoader extends IClassLoader {
7272

7373
Class<?> clazz;
7474
try {
75-
76-
//
77-
// See also [ 931385 ] Janino 2.0 throwing exception on arrays of java.io.File:
78-
//
79-
// "ClassLoader.loadClass()" and "Class.forName()" should be identical,
80-
// but "ClassLoader.loadClass("[Ljava.lang.Object;")" throws a
81-
// ClassNotFoundException under JDK 1.5.0 beta.
82-
// Unclear whether this a beta version bug and SUN will fix this in the final
83-
// release, but "Class.forName()" seems to work fine in all cases, so we
84-
// use that.
85-
//
86-
87-
// clazz = this.classLoader.loadClass(Descriptor.toClassName(descriptor));
88-
clazz = Class.forName(Descriptor.toClassName(descriptor), false, this.classLoader);
75+
clazz = this.classLoader.loadClass(Descriptor.toClassName(descriptor));
8976
} catch (ClassNotFoundException e) {
90-
if (e.getException() == null) {
91-
return null;
92-
} else
77+
78+
// Determine whether the class DOES NOT EXIST, or whether there were problems loading it. That's easier
79+
// said than done... the following seems to work:
80+
// (See also https://github.com/janino-compiler/janino/issues/104).
9381
{
94-
throw e;
82+
Throwable t = e.getCause();
83+
while (t instanceof ClassNotFoundException) t = t.getCause();
84+
if (t == null) return null;
9585
}
86+
87+
throw e;
9688
}
89+
9790
ClassLoaderIClassLoader.LOGGER.log(Level.FINE, "clazz={0}", clazz);
9891

9992
IClass result = new ReflectionIClass(clazz, this);

0 commit comments

Comments
 (0)
Please sign in to comment.