8207027: Lookup.accessClass fails for an array type in the same package when assertions are enabled

Reviewed-by: redestad, mchung
This commit is contained in:
Paul Sandoz 2018-07-11 15:35:47 -07:00
parent 8a9b0134a8
commit d808684592
3 changed files with 18 additions and 5 deletions

View File

@ -333,7 +333,6 @@ public class VerifyAccess {
* @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())

View File

@ -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 @@ public class TestAccessClass {
}
@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[][] {

View File

@ -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 @@ public class TestFindClass {
}
@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");