Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8152385

Java 1.8 does not report java.lang.NoClassDefFoundError for missing superclass of main class

    XMLWordPrintable

Details

    • 8
    • x86_64
    • generic

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_73"
      Java(TM) SE Runtime Environment (build 1.8.0_73-b02)
      Java HotSpot(TM) 64-Bit Server VM (build 25.73-b02, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux new-host-2 4.2.8-200.fc22.x86_64 #1 SMP Tue Dec 15 16:50:23 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      Java 1.8 fails to report a missing class definition error when a superclass of the main class is missing on the classpath. It instead reports that the main class itself cannot be found/loaded. This behavior is different that that found in the Java 1.7 version.


      REGRESSION. Last worked in version 7u79

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_79"
      Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create the following directory structure
      src/test/app
      src/test/missing

      2. Create the java source files.
      src/test/app/TestApplication.java
      src/test/missing/Missing.java

      3. Create a jar file containing the Missing class.
      javac src/test/missing/Missing.java
      jar cf Missing.jar -C src test/missing/Missing.class

      4. Create a jar file containing the TestApplication class.
      javac -cp ./Missing.jar src/test/app/TestApplication.java
      jar cf TestApplication.jar -C src test/app/TestApplication.class

      5. Run the test application class without a classpath reference to Missing.jar
      java -cp ./TestApplication.jar test/app/TestApplication


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected to see an error message reporting a missing class definition.
      The following is the Java 1.7 result.

      Exception in thread "main" java.lang.NoClassDefFoundError: test/missing/Missing
      at java.lang.ClassLoader.defineClass1(Native Method)
      at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
      at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
      at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
      at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
      at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
      Caused by: java.lang.ClassNotFoundException: test.missing.Missing
      at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
      at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
      ... 13 more

      ACTUAL -
      Error: Could not find or load main class test.app.TestApplication

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      No error logs were generated.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      ---- begin src/test/missing/Missing.java
      package test.missing;

      public class Missing
      {

          public Missing()
          {
              
          }
      }
      ---- end src/test/missing/Missing.java

      ---- begin src/test/app/TestApplication.java
      package test.app;

      import test.missing.Missing;

      public class TestApplication extends Missing
      {
          public static void main(String[] args)
          {
              new TestApplication().run();
          }
          
          public TestApplication()
          {
              super();
          }
          
          public void run()
          {
          }
      }
      ---- end src/test/app/TestApplication.java
      ---------- END SOURCE ----------

      Attachments

        1. Missing.jar
          0.6 kB
        2. Missing.java
          0.1 kB
        3. TestApplication.jar
          0.7 kB
        4. TestApplication.java
          0.3 kB

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: