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

Unexpected ClassnotFoundException on reflective Class#getMethod

XMLWordPrintable

    • x86_64
    • linux

      FULL PRODUCT VERSION :
      java version "9-ea"
      Java(TM) SE Runtime Environment (build 9-ea+111)
      Java HotSpot(TM) 64-Bit Server VM (build 9-ea+111, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Fedora 23, Linux 4.4.6-300.fc23.x86_64

      A DESCRIPTION OF THE PROBLEM :
      Invoking Class#getMethod throws a java.lang.NoClassDefFoundError for methods which have a type provided in a different jar dependency.

      This seems to be a regression introduced by project Jigsaw.

      REGRESSION. Last worked in version 8u77

      ADDITIONAL REGRESSION INFORMATION:
      java version "9-ea"
      Java(TM) SE Runtime Environment (build 9-ea+110)
      Java HotSpot(TM) 64-Bit Server VM (build 9-ea+110, mixed mode)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the below source code. You will need an additional dependency on your classpath, a copy can be obtained from https://repository.jboss.org/nexus/service/local/repositories/central/content/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.0.Final/jboss-transaction-api_1.2_spec-1.0.0.Final.jar

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      On Java8 or Java9 build 9-ea+110 the output is, as expected:

      > java.lang.NoSuchMethodException: Main.notexisting()
      > at java.lang.Class.getMethod(Class.java:1786)
      > at Main.main(Main.java:6)
      > All good
      ACTUAL -
      On Java9 build 9-ea+111 though I'll have this:

      > Exception in thread "main" java.lang.NoClassDefFoundError: javax/transaction/Synchronization
      > at java.lang.Class.getDeclaredMethods0(java.base@9-ea/Native Method)
      > at java.lang.Class.privateGetDeclaredMethods(java.base@9-ea/Class.java:2937)
      > at java.lang.Class.privateGetMethodRecursive(java.base@9-ea/Class.java:3282)
      > at java.lang.Class.getMethod0(java.base@9-ea/Class.java:3252)
      > at java.lang.Class.getMethod(java.base@9-ea/Class.java:1961)
      > at sun.launcher.LauncherHelper.validateMainClass(java.base@9-ea/LauncherHelper.java:648)
      > at sun.launcher.LauncherHelper.checkAndLoadMain(java.base@9-ea/LauncherHelper.java:499)
      > Caused by: java.lang.ClassNotFoundException: javax.transaction.Synchronization
      > at jdk.internal.loader.BuiltinClassLoader.loadClass(java.base@9-ea/BuiltinClassLoader.java:368)
      > at jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(java.base@9-ea/ClassLoaders.java:185)
      > at java.lang.ClassLoader.loadClass(java.base@9-ea/ClassLoader.java:419)
      > ... 7 more


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.transaction.Synchronization;

      public class Main {

      public static void main(String[] args) {
      Class clazz = Main.class;
      try {
      clazz.getMethod("notexisting", new Class[0]);
      } catch (NoSuchMethodException e) {
      e.printStackTrace();
      }
      System.out.println("All good");
      }

      public void registerSynchronization(Synchronization synchronization) {
      }

      }
      ---------- END SOURCE ----------

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

              Created:
              Updated:
              Resolved: