changeset 789:fbfb7048a523

8033745: Reflect upon Nashorn reflection Reviewed-by: ahgross, attila, jlaskey
author sundar
date Fri, 21 Feb 2014 10:01:59 +0530
parents e25af2ba7dae
children c806c8c82264
files src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java	Mon Apr 14 17:45:05 2014 +0200
+++ b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java	Fri Feb 21 10:01:59 2014 +0530
@@ -39,16 +39,38 @@
  * 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.");
     }