aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsundar <none@none>2014-02-21 17:58:33 +0530
committersundar <none@none>2014-02-21 17:58:33 +0530
commit95d5697de85e272b6044ac7b7cc61ef3c4191f45 (patch)
tree4c2451638df7d3acae1c9318905ca1113310c5fd
parentcf57c5786a88783e3a4925a3d40b1d6c400a2162 (diff)
downloadnashorn-95d5697de85e272b6044ac7b7cc61ef3c4191f45.tar.gz
8033745: Reflect upon Nashorn reflection
Reviewed-by: ahgross, attila, jlaskey
-rw-r--r--src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
index 32f30764..5997ec54 100644
--- a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
+++ b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
@@ -39,16 +39,38 @@ import jdk.nashorn.internal.runtime.Context;
* Check java reflection permission for java reflective and java.lang.invoke access from scripts
*/
final class ReflectionCheckLinker implements TypeBasedGuardingDynamicLinker{
+ private static final Class<?> STATEMENT_CLASS = getBeanClass("Statement");
+ private static final Class<?> XMLENCODER_CLASS = getBeanClass("XMLEncoder");
+ private static final Class<?> XMLDECODER_CLASS = getBeanClass("XMLDecoder");
+
+ private static Class<?> getBeanClass(final String name) {
+ try {
+ return Class.forName("java.beans." + name);
+ } catch (final ClassNotFoundException cnfe) {
+ // Possible to miss this class in other profiles.
+ return null;
+ }
+ }
+
@Override
public boolean canLinkType(final Class<?> type) {
return isReflectionClass(type);
}
private static boolean isReflectionClass(final Class<?> type) {
+ // Class or ClassLoader subclasses
if (type == Class.class || ClassLoader.class.isAssignableFrom(type)) {
return true;
}
+ // check for bean reflection
+ if ((STATEMENT_CLASS != null && STATEMENT_CLASS.isAssignableFrom(type)) ||
+ (XMLENCODER_CLASS != null && XMLENCODER_CLASS.isAssignableFrom(type)) ||
+ (XMLDECODER_CLASS != null && XMLDECODER_CLASS.isAssignableFrom(type))) {
+ return true;
+ }
+
+ // package name check
final String name = type.getName();
return name.startsWith("java.lang.reflect.") || name.startsWith("java.lang.invoke.");
}