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

Java launcher no longer prints a stack trace

XMLWordPrintable

    • 22
    • b26
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows Oracle JDK22

      A DESCRIPTION OF THE PROBLEM :
      JDK22 does not have the same built-in default stack trace handling for running a main method of a class which cannot be loaded because a dependency is missing. The same issue occurs if classes are in different jars (such as missing a jar for logger implementation)

      REGRESSION : Last worked in version 21

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile the Demo.java class below with JDK17 and test it works JDK17 and JDK22
      jdk-17\bin\javac -d classes Demo.java
      jdk-17\bin\java -cp classes Demo
      jdk-22\bin\java -cp classes Demo
      Then delete the referenced class and re-run:
         del classes\Demo$SomeDependency.class
      jdk-17\bin\java -cp classes Demo
      jdk-22\bin\java -cp classes Demo



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Run in JDK17...JDK21 reports ClassNotFoundException as expected
      jdk-17\bin\java -cp classes Demo
      Exception in thread "main" java.lang.NoClassDefFoundError: Demo$SomeDependency
              at Demo.<clinit>(Demo.java:10)
      Caused by: java.lang.ClassNotFoundException: Demo$SomeDependency
              at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
              at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
              at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)

      ACTUAL -
      Re-run in JDK22 prints nothing:
      \java\jdk-22\bin\java -cp classes Demo


      ---------- BEGIN SOURCE ----------
      // Save as Demo.java.
      public class Demo {
          static class SomeDependency {}
          private static final SomeDependency X = new SomeDependency();
          public static void main(String... args) {
              System.out.println("X="+X);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None.

      FREQUENCY : always


            szaldana Sonia Zaldana Calles
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: