diff options
author | Thomas Watson | 2021-03-23 22:42:54 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2021-03-24 10:39:31 +0000 |
commit | c030491f21ba8f270fccbac6956d2bed0655a4ee (patch) | |
tree | 891464501f0df377a938e5daedb9af8b24ee02ea | |
parent | 047b1b3e0807c18004027fbfcd44a97be1012309 (diff) | |
download | rt.equinox.framework-c030491f21ba8f270fccbac6956d2bed0655a4ee.tar.gz rt.equinox.framework-c030491f21ba8f270fccbac6956d2bed0655a4ee.tar.xz rt.equinox.framework-c030491f21ba8f270fccbac6956d2bed0655a4ee.zip |
Bug 572212 - Avoid reflecting on JRE boot classes in testsI20210324-0950
Java 16 tightens the reflective rules to obey the Java module opens
rules by default. This changes instead reflects on methods of the
framework implementation class for the bundle class loader. This change
will fail if somehow the tests run with the framework implementation
loaded in a ModuleLayer.
Change-Id: I9de041666313d6829f1009c7b3c8284013b4c558
Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
9 files changed, 105 insertions, 10 deletions
diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a1/nativetest/a1/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a1/nativetest/a1/Activator.java index 11b08b93c..0a106adb7 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a1/nativetest/a1/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a1/nativetest/a1/Activator.java @@ -19,9 +19,20 @@ import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativefile1.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a2/nativetest/a2/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a2/nativetest/a2/Activator.java index 999fb53dd..1d4b96778 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a2/nativetest/a2/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.a2/nativetest/a2/Activator.java @@ -20,8 +20,20 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativefile2.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b1/nativetest/b1/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b1/nativetest/b1/Activator.java index a1bdf02c1..38e7c5289 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b1/nativetest/b1/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b1/nativetest/b1/Activator.java @@ -20,8 +20,20 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativefile.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b2/nativetest/b2/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b2/nativetest/b2/Activator.java index 97c922ec6..e5dd5303c 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b2/nativetest/b2/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.b2/nativetest/b2/Activator.java @@ -20,8 +20,20 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativefile.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.c/nativetest/c/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.c/nativetest/c/Activator.java index 9dd155499..37219d1f4 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.c/nativetest/c/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.c/nativetest/c/Activator.java @@ -20,8 +20,20 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativecode.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.d/nativetest/d/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.d/nativetest/d/Activator.java index 9573d24df..855c0c1ed 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.d/nativetest/d/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.d/nativetest/d/Activator.java @@ -20,8 +20,20 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativecode.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.e/nativetest/e/Activator.java b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.e/nativetest/e/Activator.java index b4a3c1f9d..2c1e5cb77 100644 --- a/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.e/nativetest/e/Activator.java +++ b/bundles/org.eclipse.osgi.tests/bundles_src/nativetest.e/nativetest/e/Activator.java @@ -20,8 +20,20 @@ import org.osgi.framework.BundleContext; public class Activator implements BundleActivator { + public Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void start(BundleContext context) throws Exception { - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", new Class[] {String.class}); + Method findLibrary = findDeclaredMethod(this.getClass().getClassLoader().getClass(), "findLibrary", + String.class); findLibrary.setAccessible(true); AbstractBundleTests.simpleResults.addEvent(findLibrary.invoke(this.getClass().getClassLoader(), new Object[] {"nativecode.txt"})); } diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java index de830bc3b..4c4a5a467 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java @@ -437,6 +437,17 @@ public class BundleInstallUpdateTests extends AbstractBundleTests { is.close(); } + public static Method findDeclaredMethod(Class<?> clazz, String method, Class... args) throws NoSuchMethodException { + do { + try { + return clazz.getDeclaredMethod(method, args); + } catch (NoSuchMethodException e) { + clazz = clazz.getSuperclass(); + } + } while (clazz != null); + throw new NoSuchMethodException(method); + } + public void testEscapeZipRoot() throws IOException, BundleException, InvalidSyntaxException, NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { String entry1 = "../../escapedZipRoot1.txt"; String entry2 = "dir1/../../../escapedZipRoot2.txt"; @@ -463,8 +474,8 @@ public class BundleInstallUpdateTests extends AbstractBundleTests { } catch (ClassNotFoundException e) { // expected } - ClassLoader cl = testBundle.adapt(BundleWiring.class).getClassLoader(); - Method findLibrary = ClassLoader.class.getDeclaredMethod("findLibrary", String.class); + Object cl = testBundle.adapt(BundleWiring.class).getClassLoader(); + Method findLibrary = findDeclaredMethod(cl.getClass(), "findLibrary", String.class); findLibrary.setAccessible(true); assertNull("Found library.", findLibrary.invoke(cl, "nativeCode")); diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java index 793aa056f..0e7f0d367 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/ClassLoadingBundleTests.java @@ -1876,7 +1876,8 @@ public class ClassLoadingBundleTests extends AbstractBundleTests { ClassLoader cl = this.getClass().getClassLoader(); Enumeration resources = null; try { - Method findMethod = ClassLoader.class.getDeclaredMethod("findResources", new Class[] {String.class}); + Method findMethod = BundleInstallUpdateTests.findDeclaredMethod(cl.getClass(), "findResources", + String.class); findMethod.setAccessible(true); resources = (Enumeration) findMethod.invoke(cl, new Object[] {"test/doesnotexist.txt"}); |