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

Class::getDeclaringClass and Class::getEnclosingClass throws exception if the outer class is not present

    Details

    • Type: Bug
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None

      Description

      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

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              mchung Mandy Chung
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated: