JDK-6888126 : NoClassDefFoundError in constructor since JDK 6; Java 5 okay
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6u16
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2009-10-05
  • Updated: 2024-04-12
  • Resolved: 2017-03-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdResolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
javac 1.6.0_16

java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

java version "1.5.0_21"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_21-b01)
Java HotSpot(TM) Client VM (build 1.5.0_21-b01, mixed mode, sharing)

(Mac OS X 10.6)
java version "1.6.0_15"
Java(TM) SE Runtime Environment (build 1.6.0_15-b03-219)
Java HotSpot(TM) 64-Bit Server VM (build 14.1-b02-90, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.0.6002]

Darwin dn0a16674e.sunet 10.0.0 Darwin Kernel Version 10.0.0: Fri Jul 31 22:47:34 PDT 2009; root:xnu-1456.1.25~1/RELEASE_I386 i386

A DESCRIPTION OF THE PROBLEM :
Java 5 executes just fine [no thrown exceptions] when instantiating a class [that extends
java.awt.Component] even if it contains a method that returns an interface class [in the
same package], as long as that method is not invoked.

On the other hand, Java 6 throws a NoClassDefFoundError.

Did not look into whether the return type is an interface is a factor, nor if a constructor
other than the no-argument is used.

Works in 1.4.2.

What.class extending javax.swing.JFrame or java.awt.Frame gives the same result.

If What.class extends java.util.Properties instead, both Java 5 and Java 6 produce
the expected result.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Compile What.java and SomeInterface.java:

    javac -target 1.4 -source 1.4 What.java SomeInterface.java

2. Remove SomeInterface.class.

3. Using  1.5.0:

   java -cp . What

produces expected result.  (No exception thrown.)

4. Using 1.6.0:

  java -cp . What

produces actual result.  (Exception thrown.)


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
BEFORE new What()
 AFTER new What()

ACTUAL -
BEFORE new What()
Exception in thread "main" java.lang.NoClassDefFoundError: SomeInterface
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
        at java.lang.Class.getDeclaredMethod(Class.java:1935)
        at java.awt.Component.isCoalesceEventsOverriden(Component.java:5948)
        at java.awt.Component.access$500(Component.java:169)
        at java.awt.Component$3.run(Component.java:5902)
        at java.awt.Component$3.run(Component.java:5900)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Component.checkCoalescing(Component.java:5899)
        at java.awt.Component.<init>(Component.java:5868)
        at What.<init>(What.java:1)
        at What.main(What.java:5)
Caused by: java.lang.ClassNotFoundException: SomeInterface
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 12 more


ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.lang.NoClassDefFoundError: SomeInterface
        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
        at java.lang.Class.getDeclaredMethod(Class.java:1935)
        at java.awt.Component.isCoalesceEventsOverriden(Component.java:5948)
        at java.awt.Component.access$500(Component.java:169)
        at java.awt.Component$3.run(Component.java:5902)
        at java.awt.Component$3.run(Component.java:5900)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.awt.Component.checkCoalescing(Component.java:5899)
        at java.awt.Component.<init>(Component.java:5868)
        at What.<init>(What.java:1)
        at What.main(What.java:5)
Caused by: java.lang.ClassNotFoundException: SomeInterface
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
        ... 12 more


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
What.java:

public class What extends java.awt.Component {
  public SomeInterface returnSomeInterface() { return null; }
  public static void main(String[] args) {
    System.out.println("BEFORE new What()");
    new What();
    System.out.println(" AFTER new What()");
  }
}


SomeInterface.java:

interface SomeInterface {
}

---------- END SOURCE ----------

Release Regression From : 5.0u18
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
[~bchristi] thanks for tracking down the changes and doing this deep archeology. It's unreliable for a class to depend on a non-existent type anyway. It would not be inappropriate to close this issue as "will not fix". Linking with JDK-6823296 is okay.
15-03-2017

This should be closed as a duplicate of JDK-6823296, as the NoClassDefFoundErrors in the issue are the result of Class::[getMethod|getDeclaredMethod] resolving all types in the Class's method signatures. The exception in the Description was introduced in 6b08 by JDK-4952802 (postEvent perf. heavily depends on EventQueue length): This added the Component.coalescingEnabled instance field, resulting in the call to Class.getDeclaredMethod(): protected Component() { appContext = AppContext.getAppContext(); + coalescingEnabled = checkCoalescing(); + } ... + private final boolean coalescingEnabled; ... + private boolean checkCoalescing() { ... + final Class clazz = getClass(); + Boolean enabled = (Boolean)java.security.AccessController.doPrivileged( + new java.security.PrivilegedAction() { + public Object run() { + try { + return !emptyCoalesceMethod.equals(clazz. + getDeclaredMethod("coalesceEvents", + AWTEvent.class, AWTEvent.class)); + } catch (NoSuchMethodException e) { + return false; + } + } + } + ); ... With JDK 7 and later, the NoClassDefFoundError occurs even earlier, in the launcher. This started in 7b38 with JDK-6742159 ((launcher) improve the java launching mechanism). http://hg.openjdk.java.net/jdk7/jdk7/jdk/rev/e2c416af20bd Finding of the "main()" method was moved out of JNI up into Java, using Class.getMethod(). Fixing JDK-6823296 should prevent these NoClassDefFoundErrors.
03-03-2017

Occurs on latest JDK 9 also (b32). Fairly abstract issue but probably deserves some attention. Issue introduced in JDK 6 b08. https://bugs.openjdk.java.net/issues/?jql=fixVersion%20%3D%206%20and%20resolution%20%3D%20fixed%20and%20%22Resolved%20In%20Build%22%20%3D%20b08
30-09-2014

EVALUATION The current implementation of Class.getDeclaredMethod and getMethod resolve all types declared in the method signature (6823296). Need further investigation to determine what has changed in jdk 6 to cause the change of behavior. If What.java is changed to extend java.util.Properties, both JDK 5 and 6 work as expected (no exception thrown) as the exception was trigged from java.awt.Component initialization that no longer exists in this case. However, jdk 7 introduces any regression: Exception in thread "main" java.lang.NoClassDefFoundError: SomeInterface at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2440) at java.lang.Class.getMethod0(Class.java:2683) at java.lang.Class.getMethod(Class.java:1618) at sun.launcher.LauncherHelper.signatureDiagnostic(LauncherHelper.java:210) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:202) Caused by: java.lang.ClassNotFoundException: SomeInterface at java.net.URLClassLoader$1.run(URLClassLoader.java:299) at java.net.URLClassLoader$1.run(URLClassLoader.java:288) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:287) at java.lang.ClassLoader.loadClass(ClassLoader.java:422) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:325) at java.lang.ClassLoader.loadClass(ClassLoader.java:355) ... 6 more
21-07-2010