8207027: Lookup.accessClass fails for an array type in the same package when assertions are enabled
authorpsandoz
Wed, 11 Jul 2018 15:35:47 -0700
changeset 51071 040880bdd0d4
parent 51070 2f4c3cac8556
child 51072 6a037fd949e4
8207027: Lookup.accessClass fails for an array type in the same package when assertions are enabled Reviewed-by: redestad, mchung
src/java.base/share/classes/sun/invoke/util/VerifyAccess.java
test/jdk/java/lang/invoke/t8150782/TestAccessClass.java
test/jdk/java/lang/invoke/t8150782/TestFindClass.java
--- a/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java	Wed Jul 11 16:11:10 2018 +0200
+++ b/src/java.base/share/classes/sun/invoke/util/VerifyAccess.java	Wed Jul 11 15:35:47 2018 -0700
@@ -333,7 +333,6 @@
      * @return whether they are in the same package
      */
     public static boolean isSamePackage(Class<?> class1, Class<?> class2) {
-        assert(!class1.isArray() && !class2.isArray());
         if (class1 == class2)
             return true;
         if (class1.getClassLoader() != class2.getClassLoader())
--- a/test/jdk/java/lang/invoke/t8150782/TestAccessClass.java	Wed Jul 11 16:11:10 2018 +0200
+++ b/test/jdk/java/lang/invoke/t8150782/TestAccessClass.java	Wed Jul 11 15:35:47 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -24,6 +24,7 @@
  */
 
 /* @test
+ * @bug 8150782 8207027
  * @compile TestAccessClass.java TestCls.java
  * @run testng/othervm -ea -esa test.java.lang.invoke.t8150782.TestAccessClass
  */
@@ -54,11 +55,17 @@
     }
 
     @Test
-    public void returnsSameClass() throws IllegalAccessException, ClassNotFoundException {
+    public void returnsSameClassInSamePackage() throws IllegalAccessException, ClassNotFoundException {
         Class<?> aClass = lookup().accessClass(Class1.class);
         assertEquals(Class1.class, aClass);
     }
 
+    @Test
+    public void returnsSameArrayClassInSamePackage() throws IllegalAccessException, ClassNotFoundException {
+        Class<?> aClass = lookup().accessClass(Class1[].class);
+        assertEquals(Class1[].class, aClass);
+    }
+
     @DataProvider
     Object[][] illegalAccessAccess() {
         return new Object[][] {
--- a/test/jdk/java/lang/invoke/t8150782/TestFindClass.java	Wed Jul 11 16:11:10 2018 +0200
+++ b/test/jdk/java/lang/invoke/t8150782/TestFindClass.java	Wed Jul 11 15:35:47 2018 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2018, 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
@@ -24,6 +24,7 @@
  */
 
 /* @test
+ * @bug 8150782 8207027
  * @compile TestFindClass.java TestCls.java
  * @run testng/othervm -ea -esa test.java.lang.invoke.t8150782.TestFindClass
  */
@@ -56,11 +57,17 @@
     }
 
     @Test
-    public void returnsRequestedClass() throws IllegalAccessException, ClassNotFoundException {
+    public void returnsRequestedClassInSamePackage() throws IllegalAccessException, ClassNotFoundException {
         Class<?> aClass = lookup().findClass(PACKAGE_PREFIX + "TestFindClass$Class1");
         assertEquals(Class1.class, aClass);
     }
 
+    @Test
+    public void returnsRequestedArrayClassInSamePackage() throws IllegalAccessException, ClassNotFoundException {
+        Class<?> aClass = lookup().findClass("[L" + PACKAGE_PREFIX + "TestFindClass$Class1;");
+        assertEquals(Class1[].class, aClass);
+    }
+
     @Test(expectedExceptions = {ClassNotFoundException.class})
     public void classNotFoundExceptionTest() throws IllegalAccessException, ClassNotFoundException {
         lookup().findClass(PACKAGE_PREFIX + "TestFindClass$NonExistent");