Skip to content
Permalink
Browse files
minor refactor: reduce removal warnings
  • Loading branch information
paulk-asert committed Apr 17, 2022
1 parent 4b988bb commit e6b1637d8a37c6a70b02af2991cf4eb7bacba782
Showing 6 changed files with 12 additions and 7 deletions.
@@ -831,6 +831,7 @@ public Boolean isShouldRecompile() {
* @throws ClassNotFoundException if the class could not be found
* @throws CompilationFailedException if the source file could not be compiled
*/
@SuppressWarnings("removal") // TODO a future Groovy version should remove the security check
public Class loadClass(final String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)
throws ClassNotFoundException, CompilationFailedException {
// look into cache
@@ -232,6 +232,7 @@ public boolean isCachable() {
return cachable;
}

@SuppressWarnings("removal") // TODO a future Groovy version should remove the security check
private static CodeSource createCodeSource(final String codeBase) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
@@ -455,6 +455,7 @@ public Object evaluate(String scriptText, String fileName) throws CompilationFai
* Evaluates some script against the current Binding and returns the result.
* The .class file created from the script is given the supplied codeBase
*/
@SuppressWarnings("removal") // TODO a future Groovy version should skip security checks
public Object evaluate(final String scriptText, final String fileName, final String codeBase) throws CompilationFailedException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
@@ -25,8 +25,8 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ReflectPermission;
import java.security.AccessControlException;

@SuppressWarnings("removal") // TODO future Groovy versions should deprecate then remove this class
final class AccessPermissionChecker {

private static final ReflectPermission REFLECT_PERMISSION = new ReflectPermission("suppressAccessChecks");
@@ -55,27 +55,27 @@ private static boolean packageCanNotBeAddedAnotherClass(Class<?> declaringClass)
static void checkAccessPermission(Method method) {
try {
checkAccessPermission(method.getDeclaringClass(), method.getModifiers(), method.isAccessible());
} catch (AccessControlException e) {
} catch (java.security.AccessControlException e) {
throw createCacheAccessControlExceptionOf(method, e);
}
}

static void checkAccessPermission(Constructor constructor) {
try {
checkAccessPermission(constructor.getDeclaringClass(), constructor.getModifiers(), constructor.isAccessible());
} catch (AccessControlException e) {
} catch (java.security.AccessControlException e) {
throw createCacheAccessControlExceptionOf(constructor, e);
}
}

private static CacheAccessControlException createCacheAccessControlExceptionOf(Method method, AccessControlException e) {
private static CacheAccessControlException createCacheAccessControlExceptionOf(Method method, java.security.AccessControlException e) {
return new CacheAccessControlException(
"Groovy object can not access method " + method.getName()
+ " cacheAccessControlExceptionOf class " + method.getDeclaringClass().getName()
+ " with modifiers \"" + Modifier.toString(method.getModifiers()) + "\"", e);
}

private static CacheAccessControlException createCacheAccessControlExceptionOf(Constructor constructor, AccessControlException e) {
private static CacheAccessControlException createCacheAccessControlExceptionOf(Constructor constructor, java.security.AccessControlException e) {
return new CacheAccessControlException(
"Groovy object can not access constructor " + constructor.getName()
+ " cacheAccessControlExceptionOf class " + constructor.getDeclaringClass().getName()
@@ -85,12 +85,12 @@ private static CacheAccessControlException createCacheAccessControlExceptionOf(C
static void checkAccessPermission(Field field) {
try {
checkAccessPermission(field.getDeclaringClass(), field.getModifiers(), field.isAccessible());
} catch (AccessControlException e) {
} catch (java.security.AccessControlException e) {
throw createCacheAccessControlExceptionOf(field, e);
}
}

private static CacheAccessControlException createCacheAccessControlExceptionOf(Field field, AccessControlException e) {
private static CacheAccessControlException createCacheAccessControlExceptionOf(Field field, java.security.AccessControlException e) {
return new CacheAccessControlException(
"Groovy object can not access field " + field.getName()
+ " cacheAccessControlExceptionOf class " + field.getDeclaringClass().getName()
@@ -272,6 +272,7 @@ private static boolean classShouldBeIgnored(final Class c, final Collection<Stri
|| extraIgnoredPackages.contains(c.getPackage().getName())))));
}

@SuppressWarnings("removal") // TODO a future Groovy version should deprecate this class
private static class ClassContextHelper extends SecurityManager {
@Override
public Class[] getClassContext() {
@@ -100,6 +100,7 @@ public Object coerceArgument(Object argument) {
}
}

@SuppressWarnings("removal") // TODO a future Groovy version should remove the security check
private static Method[] getDeclaredMethods(final Class c) {
try {
Method[] methods = VMPluginFactory.getPlugin().doPrivileged((PrivilegedAction<Method[]>) c::getDeclaredMethods);

0 comments on commit e6b1637

Please sign in to comment.