|
23 | 23 |
|
24 | 24 | /*
|
25 | 25 | * @test
|
26 |
| - * @bug 8227415 8254975 |
27 |
| - * @run testng/othervm p.SuperMethodTest |
| 26 | + * @bug 8227415 8254975 8270056 |
| 27 | + * @run testng/othervm p.ProtectedMethodInOtherPackage |
28 | 28 | * @summary method reference to a protected method inherited from its
|
29 | 29 | * superclass in a different runtime package where
|
30 | 30 | * lambda proxy class has no access to it.
|
|
50 | 50 | import org.testng.annotations.Test;
|
51 | 51 | import static org.testng.Assert.*;
|
52 | 52 |
|
53 |
| -public class SuperMethodTest { |
| 53 | +public class ProtectedMethodInOtherPackage { |
54 | 54 | @Test
|
55 | 55 | public static void remotePackageSameLoader() {
|
56 | 56 | Sub_I sub = new Sub_I();
|
@@ -101,6 +101,30 @@ public static void splitPackage() throws Throwable {
|
101 | 101 | ((Runnable) get.invoke(b)).run();
|
102 | 102 | }
|
103 | 103 |
|
| 104 | + @Test |
| 105 | + public static void protectedStaticMethodInSplitPackage() throws Throwable { |
| 106 | + ClassLoader parent = new Loader("loader-A1", null, A1.class); |
| 107 | + ClassLoader loader = new Loader("loader-B1", parent, B1.class); |
| 108 | + Class<?> aClass1 = Class.forName(A1.class.getName(), false, loader); |
| 109 | + Class<?> bClass1 = Class.forName(B1.class.getName(), false, loader); |
| 110 | + assertTrue(aClass1.getClassLoader() == parent); |
| 111 | + assertTrue(bClass1.getClassLoader() == loader); |
| 112 | + assertEquals(aClass1.getPackageName(), bClass1.getPackageName()); |
| 113 | + |
| 114 | + // verify subclass can access a static protected method inherited from |
| 115 | + // its superclass in a split package |
| 116 | + MethodHandle test = MethodHandles.lookup() |
| 117 | + .findStatic(bClass1, "test", MethodType.methodType(void.class)); |
| 118 | + test.invoke(); |
| 119 | + |
| 120 | + // verify lambda can access a static protected method inherited from |
| 121 | + // a superclass of the host class where the superclass is in |
| 122 | + // a split package (not the same runtime package as the host class) |
| 123 | + MethodHandle get = MethodHandles.lookup() |
| 124 | + .findStatic(bClass1, "get", MethodType.methodType(Runnable.class)); |
| 125 | + ((Runnable) get.invoke()).run(); |
| 126 | + } |
| 127 | + |
104 | 128 | static class Loader extends URLClassLoader {
|
105 | 129 | static final Path CLASSES_DIR = Paths.get(System.getProperty("test.class.path"));
|
106 | 130 | private final Class<?> c;
|
@@ -138,4 +162,17 @@ public void test() {
|
138 | 162 | func();
|
139 | 163 | }
|
140 | 164 | }
|
| 165 | + |
| 166 | + public static class A1 { |
| 167 | + protected static void func() { } |
| 168 | + } |
| 169 | + |
| 170 | + public static class B1 extends A1 { |
| 171 | + public static Runnable get() { |
| 172 | + return A1::func; |
| 173 | + } |
| 174 | + public static void test() { |
| 175 | + func(); |
| 176 | + } |
| 177 | + } |
141 | 178 | }
|
1 commit comments
openjdk-notifier[bot] commentedon Jul 14, 2021
Review
Issues