From dbadfa85848b5a0849917a73c17458614dfdb633 Mon Sep 17 00:00:00 2001 From: Arno Unkrig Date: Wed, 31 Aug 2022 13:04:12 +0200 Subject: [PATCH] Fixed an AccessControlException with JRE 7. --- .../util/reflect/ByteArrayClassLoader.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/commons-compiler/src/main/java/org/codehaus/commons/compiler/util/reflect/ByteArrayClassLoader.java b/commons-compiler/src/main/java/org/codehaus/commons/compiler/util/reflect/ByteArrayClassLoader.java index 98003482..cf34a5b8 100644 --- a/commons-compiler/src/main/java/org/codehaus/commons/compiler/util/reflect/ByteArrayClassLoader.java +++ b/commons-compiler/src/main/java/org/codehaus/commons/compiler/util/reflect/ByteArrayClassLoader.java @@ -27,6 +27,8 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; +import java.security.AccessControlException; +import java.security.ProtectionDomain; import java.util.Collections; import java.util.Map; @@ -82,12 +84,20 @@ class ByteArrayClassLoader extends ClassLoader { // JNLP. See // http://jira.codehaus.org/browse/JANINO-104 // http://www.nabble.com/-Help-jel--java.security.AccessControlException-to13073723.html + ProtectionDomain protectionDomain; + try { + + // With JRE 7, "getProtectionDomain" sometimes is not allowed. + protectionDomain = this.getClass().getProtectionDomain(); + } catch (AccessControlException ace) { + protectionDomain = null; + } return super.defineClass( - name, // name - data, // b - 0, // off - data.length, // len - this.getClass().getProtectionDomain() // protectionDomain + name, // name + data, // b + 0, // off + data.length, // len + protectionDomain // protectionDomain ); }