8073361: Missing doPrivileged in com.sun.xml.internal.bind.v2.ClassFactory
authormchung
Wed, 25 Feb 2015 14:51:12 -0800
changeset 29142 49c84c7ed2ad
parent 29141 c0bacc2ef380
child 29143 eccafe6808d1
8073361: Missing doPrivileged in com.sun.xml.internal.bind.v2.ClassFactory Reviewed-by: mullan, mkos
jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/ClassFactory.java
--- a/jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/ClassFactory.java	Tue Feb 24 12:45:47 2015 -0800
+++ b/jaxws/src/java.xml.bind/share/classes/com/sun/xml/internal/bind/v2/ClassFactory.java	Wed Feb 25 14:51:12 2015 -0800
@@ -30,6 +30,8 @@
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 import java.lang.ref.WeakReference;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.util.Map;
 import java.util.WeakHashMap;
 import java.util.logging.Level;
@@ -85,19 +87,25 @@
         if(consRef!=null)
             cons = consRef.get();
         if(cons==null) {
-            try {
-                cons = clazz.getDeclaredConstructor(emptyClass);
-            } catch (NoSuchMethodException e) {
-                logger.log(Level.INFO,"No default constructor found on "+clazz,e);
-                NoSuchMethodError exp;
-                if(clazz.getDeclaringClass()!=null && !Modifier.isStatic(clazz.getModifiers())) {
-                    exp = new NoSuchMethodError(Messages.NO_DEFAULT_CONSTRUCTOR_IN_INNER_CLASS.format(clazz.getName()));
-                } else {
-                    exp = new NoSuchMethodError(e.getMessage());
+            cons = AccessController.doPrivileged(new PrivilegedAction<Constructor<T>>() {
+                @Override
+                public Constructor<T> run() {
+                    try {
+                        return clazz.getDeclaredConstructor(emptyClass);
+                    } catch (NoSuchMethodException e) {
+                        logger.log(Level.INFO,"No default constructor found on "+clazz,e);
+                        NoSuchMethodError exp;
+                        if(clazz.getDeclaringClass()!=null && !Modifier.isStatic(clazz.getModifiers())) {
+                            exp = new NoSuchMethodError(Messages.NO_DEFAULT_CONSTRUCTOR_IN_INNER_CLASS
+                                                                .format(clazz.getName()));
+                        } else {
+                            exp = new NoSuchMethodError(e.getMessage());
+                        }
+                        exp.initCause(e);
+                        throw exp;
+                    }
                 }
-                exp.initCause(e);
-                throw exp;
-            }
+            });
 
             int classMod = clazz.getModifiers();