Details
-
Bug
-
Resolution: Fixed
-
P3
-
None
-
None
-
Mac only issue
-
b89
-
x86
-
os_x
Description
With jdk8 recent build on Mac, we get the NoClassDefFoundError from Class.forName instead of ClassNotFoundException as specified:
simple Java example:
class Main {
public static void main(String[] args) throws Exception {
Class.forName("java.awt.event");
}
}
The above code throws NoClassDefFoundError rather than ClassNotFoundException:
Exception in thread "main" java.lang.NoClassDefFoundError: java/awt/event (wrong name: java/awt/Event)
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1005)
at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:257)
This seems to be Mac specific. We have not been able to reproduce this one on Ubuntu for example.
nashorn checks if a qualified name is a (potential) java package or a class using Class.forName. If that throws ClassNotFoundException, nashorn treats the name as package prefix. If not, the qualified name is resolved to a java class. The current issue was found when a nashorn test that attempts java.awt.event.ActionListerner in script. "java.awt.event" prefix should have resolved as package name - but because nashorn gets NoClassDefFoundError which is not expected/caught, the test ends up throwing error.
simple Java example:
class Main {
public static void main(String[] args) throws Exception {
Class.forName("java.awt.event");
}
}
The above code throws NoClassDefFoundError rather than ClassNotFoundException:
Exception in thread "main" java.lang.NoClassDefFoundError: java/awt/event (wrong name: java/awt/Event)
at java.lang.ClassLoader.findBootstrapClass(Native Method)
at java.lang.ClassLoader.findBootstrapClassOrNull(ClassLoader.java:1005)
at java.lang.ClassLoader.loadClass(ClassLoader.java:412)
at java.lang.ClassLoader.loadClass(ClassLoader.java:410)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:257)
This seems to be Mac specific. We have not been able to reproduce this one on Ubuntu for example.
nashorn checks if a qualified name is a (potential) java package or a class using Class.forName. If that throws ClassNotFoundException, nashorn treats the name as package prefix. If not, the qualified name is resolved to a java class. The current issue was found when a nashorn test that attempts java.awt.event.ActionListerner in script. "java.awt.event" prefix should have resolved as package name - but because nashorn gets NoClassDefFoundError which is not expected/caught, the test ends up throwing error.