You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2022/02/04 01:06:00 UTC
[groovy] 01/02: JDK18 test fixes - setting security manager is an UnsupportedOperationException from 18 onwards as part of JEP-411
This is an automated email from the ASF dual-hosted git repository.
paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
commit f150b33d3b3388de3b43ca4d30c94aad2139689e
Author: Paul King <pa...@asert.com.au>
AuthorDate: Thu Feb 3 11:44:48 2022 +1000
JDK18 test fixes - setting security manager is an UnsupportedOperationException from 18 onwards as part of JEP-411
---
.../org/codehaus/groovy/reflection/SecurityTest.java | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/src/test/org/codehaus/groovy/reflection/SecurityTest.java b/src/test/org/codehaus/groovy/reflection/SecurityTest.java
index cdc4b7c..2020420 100644
--- a/src/test/org/codehaus/groovy/reflection/SecurityTest.java
+++ b/src/test/org/codehaus/groovy/reflection/SecurityTest.java
@@ -138,12 +138,14 @@ public class SecurityTest extends GroovyTestCase {
}
public void testInvokesPublicMethodsWithoutChecks() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("publicMethod");
System.setSecurityManager(restrictiveSecurityManager);
assertTrue(invokesCachedMethod());
}
public void testReturnsAccesiblePublicMethodsWithoutChecks() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("publicMethod");
System.setSecurityManager(restrictiveSecurityManager);
assertEquals("publicMethod", cachedMethodUnderTest.setAccessible().getName());
@@ -151,6 +153,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testAccessesPublicFieldsWithoutChecks() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedFieldUnderTest = createCachedField("publicField");
System.setSecurityManager(restrictiveSecurityManager);
TestClass object = new TestClass();
@@ -164,6 +167,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testAccessesPrivateFieldsWithoutSecurityManager() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedFieldUnderTest = createCachedField("privateField");
System.setSecurityManager(null);
TestClass object = new TestClass();
@@ -172,6 +176,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testReturnsAccesiblePrivateMethodsWithoutSecurityManager() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("privateMethod");
System.setSecurityManager(null);
assertEquals("privateMethod", cachedMethodUnderTest.setAccessible().getName());
@@ -179,6 +184,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testChecksReflectPermissionForInvokeOnPrivateMethods() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("privateMethod");
System.setSecurityManager(restrictiveSecurityManager);
try {
@@ -191,6 +197,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testChecksReflectPermissionForFieldAccessOnPrivateFields() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedFieldUnderTest = createCachedField("privateField");
System.setSecurityManager(restrictiveSecurityManager);
TestClass object = new TestClass();
@@ -210,6 +217,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testChecksReflectPermissionForMethodAccessOnPrivateMethods() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("privateMethod");
System.setSecurityManager(restrictiveSecurityManager);
try {
@@ -228,6 +236,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testInvokesPackagePrivateMethodsWithoutChecksInNonRestrictedPackages() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("packagePrivateMethod");
System.setSecurityManager(restrictiveSecurityManager);
assertTrue(invokesCachedMethod());
@@ -235,9 +244,7 @@ public class SecurityTest extends GroovyTestCase {
public void testChecksReflectPermissionForInvokeOnPackagePrivateMethodsInRestrictedJavaPackages() throws Exception {
// FIX_JDK9 remove this exemption for JDK9
- if (isAtLeastJdk("9.0")) {
- return;
- }
+ if (isAtLeastJdk("9.0")) return;
cachedMethodUnderTest = createCachedMethod(ClassLoader.class, "getBootstrapClassPath");
System.setSecurityManager(restrictiveSecurityManager);
@@ -251,6 +258,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testInvokesProtectedMethodsWithoutChecks() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod("protectedMethod");
System.setSecurityManager(restrictiveSecurityManager);
assertTrue(invokesCachedMethod());
@@ -278,6 +286,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testInvokesPrivateMethodsInGroovyObjectsWithoutChecks() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
cachedMethodUnderTest = createCachedMethod(TestGroovyClass.class, "privateMethod");
TestGroovyClass object = new TestGroovyClass();
System.setSecurityManager(restrictiveSecurityManager);
@@ -286,6 +295,7 @@ public class SecurityTest extends GroovyTestCase {
}
public void testAccessesPrivateFieldsInGroovyObjectsWithoutChecks() throws Exception {
+ if (isAtLeastJdk("18.0")) return;
Field field = TestGroovyClass.class.getDeclaredField("privateField");
field.setAccessible(true);
cachedFieldUnderTest = new CachedField(field);