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

Can't get annotations that are present on packages in -Xbootclasspath/a

    XMLWordPrintable

    Details

    • Subcomponent:
    • Introduced In Version:
      9
    • Resolved In Build:
      b07
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      A DESCRIPTION OF THE PROBLEM :
      Can't get annotations that are present on packages in -Xbootclasspath/a.

      Perhaps the cause of this problem is that the class loader for -Xbootclasspath/a
      (jdk.internal.loader.ClassLoaders.BOOT_LOADER) can't reference the class java.lang.Object
      loaded by the bootstrap class loader.

      Because the class package-info extends the class java.lang.Object,
      the class java.lang.Object is loaded or referenced in defining the class package-info.

      If the class package-info is in -Xbootclasspath/a,
      the class loader for -Xbootclasspath/a tries to load the class java.lang.Object.

      But the class loader for -Xbootclasspath/a can't reference the class java.lang.Object
      loaded by the bootstrap class loader.

      So, the class loader for -Xbootclasspath/a tries to find and define the class java.lang.Object.

      Then an exception occurrs because ClassLoader.preDefineClass prohibits class loaders
      other than the platform class loader from loading classes in packages "java.*".

      Perhaps this problem occurrs Package.getPackageInfo only.
      Loading the class package-info in -Xbootclasspath/a by Class.forName
      or ClassLoader.loadClass is successful.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. compile a bootclasspath library
      cd boot-lib
      javac sample/MyAnnotation.java sample/Foo.java sample/package-info.java
      jar cf ../boot-lib.jar sample/MyAnnotation.class sample/Foo.class sample/package-info.class
      cd ..

      2. compile a sample application
      javac -cp boot-lib.jar Sample.java

      3. run the sample with boot-lib.jar on bootclasspath
      java -Xbootclasspath/a:boot-lib.jar -cp . Sample

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Print "Success"
      ACTUAL -
      Exception occurred.

      Exception in thread "main" java.lang.SecurityException: Prohibited package name: java.lang
              at java.base/java.lang.ClassLoader.preDefineClass(ClassLoader.java:898)
              at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1106)
              at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:206)
              at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:761)
              at java.base/jdk.internal.loader.BuiltinClassLoader.findClassInModuleOrNull(BuiltinClassLoader.java:682)
              at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:607)
              at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
              at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
              at java.base/java.lang.ClassLoader.defineClass1(Native Method)
              at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
              at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
              at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
              at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
              at java.base/jdk.internal.loader.BuiltinClassLoader.findClass(BuiltinClassLoader.java:568)
              at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:633)
              at java.base/java.lang.Package.getPackageInfo(Package.java:420)
              at java.base/java.lang.Package.getAnnotations(Package.java:467)
              at Sample.main(Sample.java:5)

      ---------- BEGIN SOURCE ----------
      - boot-lib/sample/MyAnnotation.java
      package sample;

      import java.lang.annotation.ElementType;
      import java.lang.annotation.Retention;
      import java.lang.annotation.RetentionPolicy;
      import java.lang.annotation.Target;

      @Target(ElementType.PACKAGE)
      @Retention(RetentionPolicy.RUNTIME)
      public @interface MyAnnotation {
      }

      - boot-lib/sample/Foo.java
      package sample;

      public class Foo {
      }

      - boot-lib/sample/package-info.java
      @MyAnnotation
      package sample;

      - Sample.java
      public class Sample {
          public static void main(String[] args) {
              Class<?> c = sample.Foo.class;
              Package p = c.getPackage();
              p.getAnnotations();
              System.out.println("Success");
          }
      }

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

      FREQUENCY : always


        Attachments

        1. Sample.java
          0.2 kB
        2. sample.zip
          2 kB

          Activity

            People

            Assignee:
            mchung Mandy Chung
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: