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

Unspecified exception thrown by Class::getDeclaringClass and Class::getEnclosingClass if the outer class is not present

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • 8
    • core-libs
    • None

      public class X {
          public class Y {}
      }

      The outer class of Y is X. `Y.class.getDeclaringClass()` returns `Class` instance representing X.

      The behavior is not specified if X cannot be found. The current implementation throws NCDFE.
       
      Exception in thread "main" java.lang.NoClassDefFoundError: X
      at java.base/java.lang.Class.getDeclaringClass0(Native Method)
      at java.base/java.lang.Class.getEnclosingClass(Class.java:1536)
      at Test.main(Test.java:5)
      Caused by: java.lang.ClassNotFoundException: X
      at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:602)
      at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
      at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
      ... 3 more

      The APIs whose implementation inspects `InnerAttributes` or `EnclosingMethod` method have simiar issue such as:
      Class::getDeclaringClass, Class::getEnclosingClass, Class::getDeclaredClasses

            Unassigned Unassigned
            mchung Mandy Chung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: