changeset 53915:929f0c7e019b

8218419: Can't get annotations that are present on packages in -Xbootclasspath/a Reviewed-by: alanb
author mchung
date Wed, 06 Feb 2019 10:53:13 -0800
parents da5dc7e654aa
children 021917019cda
files src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java test/jdk/java/lang/Package/bootclasspath/GetPackageFromBootClassPath.java test/jdk/java/lang/Package/bootclasspath/boot/foo/Foo.java test/jdk/java/lang/Package/bootclasspath/boot/foo/MyAnnotation.java test/jdk/java/lang/Package/bootclasspath/boot/foo/package-info.java
diffstat 6 files changed, 157 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java	Wed Feb 06 13:30:27 2019 -0500
+++ b/src/java.base/share/classes/jdk/internal/loader/BuiltinClassLoader.java	Wed Feb 06 10:53:13 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -638,7 +638,7 @@
      * binary name. This method returns {@code null} when the class is not
      * found.
      */
-    protected Class<?> loadClassOrNull(String cn) {
+    protected final Class<?> loadClassOrNull(String cn) {
         return loadClassOrNull(cn, false);
     }
 
--- a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	Wed Feb 06 13:30:27 2019 -0500
+++ b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	Wed Feb 06 10:53:13 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -114,7 +114,7 @@
         }
 
         @Override
-        protected Class<?> loadClassOrNull(String cn) {
+        protected Class<?> loadClassOrNull(String cn, boolean resolve) {
             return JLA.findBootstrapClassOrNull(this, cn);
         }
     };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/Package/bootclasspath/GetPackageFromBootClassPath.java	Wed Feb 06 10:53:13 2019 -0800
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8218419
+ * @library /test/lib
+ * @modules jdk.compiler
+ * @build jdk.test.lib.compiler.CompilerUtils
+ * @run driver GetPackageFromBootClassPath setup
+ * @run main/othervm -Xbootclasspath/a:boot GetPackageFromBootClassPath
+ */
+
+import java.lang.annotation.Annotation;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+
+public class GetPackageFromBootClassPath {
+    public static void main(String... args) throws Exception {
+        if (args.length == 0) {
+            test();
+        } else {
+            setupBootLib();
+        }
+    }
+
+    private static void test() throws Exception {
+        Class<?> c = Class.forName("foo.Foo", false, null);
+        Package p = c.getPackage();
+        Annotation[] annotations = p.getAnnotations();
+        Class<?> annType = Class.forName("foo.MyAnnotation", false, null);
+        if (annotations.length != 1 ||
+            annotations[0].annotationType() != annType) {
+            throw new RuntimeException("Expected foo.MyAnnotation but got " +
+                Arrays.toString(annotations));
+        }
+    }
+
+    private static void setupBootLib() throws Exception {
+        Path testSrc = Paths.get(System.getProperty("test.src"), "boot");
+        Path bootDir = Paths.get("boot");
+        if (!jdk.test.lib.compiler.CompilerUtils.compile(testSrc, bootDir)) {
+            throw new RuntimeException("compilation fails");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/Package/bootclasspath/boot/foo/Foo.java	Wed Feb 06 10:53:13 2019 -0800
@@ -0,0 +1,27 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package foo;
+
+public class Foo {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/Package/bootclasspath/boot/foo/MyAnnotation.java	Wed Feb 06 10:53:13 2019 -0800
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package foo;
+
+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 {
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/jdk/java/lang/Package/bootclasspath/boot/foo/package-info.java	Wed Feb 06 10:53:13 2019 -0800
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+@MyAnnotation
+package foo;