changeset 6649:2790e9ace697

8013744: Better tabling for AWT Reviewed-by: art, malenkov, skoivu
author alexsch
date Tue, 21 May 2013 19:04:50 +0400
parents 0783b9189e71
children 10cd25a8c020
files src/share/classes/javax/swing/JTable.java src/share/classes/javax/swing/UIDefaults.java src/share/classes/javax/swing/text/DefaultFormatter.java src/share/classes/javax/swing/text/NumberFormatter.java src/share/classes/sun/swing/SwingLazyValue.java src/share/classes/sun/swing/SwingUtilities2.java
diffstat 6 files changed, 40 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/javax/swing/JTable.java	Tue May 21 13:56:39 2013 +0400
+++ b/src/share/classes/javax/swing/JTable.java	Tue May 21 19:04:50 2013 +0400
@@ -52,6 +52,7 @@
 
 import javax.print.attribute.*;
 import javax.print.PrintService;
+import sun.reflect.misc.ReflectUtil;
 
 import sun.swing.SwingUtilities2;
 import sun.swing.SwingUtilities2.Section;
@@ -5460,14 +5461,15 @@
             // they have the option to replace the value with
             // null or use escape to restore the original.
             // For Strings, return "" for backward compatibility.
-            if ("".equals(s)) {
-                if (constructor.getDeclaringClass() == String.class) {
-                    value = s;
-                }
-                super.stopCellEditing();
-            }
-
             try {
+                if ("".equals(s)) {
+                    if (constructor.getDeclaringClass() == String.class) {
+                        value = s;
+                    }
+                    super.stopCellEditing();
+                }
+
+                SwingUtilities2.checkAccess(constructor.getModifiers());
                 value = constructor.newInstance(new Object[]{s});
             }
             catch (Exception e) {
@@ -5491,6 +5493,8 @@
                 if (type == Object.class) {
                     type = String.class;
                 }
+                ReflectUtil.checkPackageAccess(type);
+                SwingUtilities2.checkAccess(type.getModifiers());
                 constructor = type.getConstructor(argTypes);
             }
             catch (Exception e) {
--- a/src/share/classes/javax/swing/UIDefaults.java	Tue May 21 13:56:39 2013 +0400
+++ b/src/share/classes/javax/swing/UIDefaults.java	Tue May 21 19:04:50 2013 +0400
@@ -53,6 +53,7 @@
 
 import sun.reflect.misc.MethodUtil;
 import sun.reflect.misc.ReflectUtil;
+import sun.swing.SwingUtilities2;
 import sun.util.CoreResourceBundleControl;
 
 /**
@@ -1101,7 +1102,7 @@
                         }
                         ReflectUtil.checkPackageAccess(className);
                         c = Class.forName(className, true, (ClassLoader)cl);
-                        checkAccess(c.getModifiers());
+                        SwingUtilities2.checkAccess(c.getModifiers());
                         if (methodName != null) {
                             Class[] types = getClassArray(args);
                             Method m = c.getMethod(methodName, types);
@@ -1109,7 +1110,7 @@
                         } else {
                             Class[] types = getClassArray(args);
                             Constructor constructor = c.getConstructor(types);
-                            checkAccess(constructor.getModifiers());
+                            SwingUtilities2.checkAccess(constructor.getModifiers());
                             return constructor.newInstance(args);
                         }
                     } catch(Exception e) {
@@ -1124,13 +1125,6 @@
             }, acc);
         }
 
-        private void checkAccess(int modifiers) {
-            if(System.getSecurityManager() != null &&
-                    !Modifier.isPublic(modifiers)) {
-                throw new SecurityException("Resource is not accessible");
-            }
-        }
-
         /*
          * Coerce the array of class types provided into one which
          * looks the way the Reflection APIs expect.  This is done
--- a/src/share/classes/javax/swing/text/DefaultFormatter.java	Tue May 21 13:56:39 2013 +0400
+++ b/src/share/classes/javax/swing/text/DefaultFormatter.java	Tue May 21 19:04:50 2013 +0400
@@ -24,7 +24,8 @@
  */
 package javax.swing.text;
 
-import sun.reflect.misc.ConstructorUtil;
+import sun.reflect.misc.ReflectUtil;
+import sun.swing.SwingUtilities2;
 
 import java.io.Serializable;
 import java.lang.reflect.*;
@@ -247,7 +248,9 @@
             Constructor cons;
 
             try {
-                cons = ConstructorUtil.getConstructor(vc, new Class[]{String.class});
+                ReflectUtil.checkPackageAccess(vc);
+                SwingUtilities2.checkAccess(vc.getModifiers());
+                cons = vc.getConstructor(new Class[]{String.class});
 
             } catch (NoSuchMethodException nsme) {
                 cons = null;
@@ -255,6 +258,7 @@
 
             if (cons != null) {
                 try {
+                    SwingUtilities2.checkAccess(cons.getModifiers());
                     return cons.newInstance(new Object[] { string });
                 } catch (Throwable ex) {
                     throw new ParseException("Error creating instance", 0);
--- a/src/share/classes/javax/swing/text/NumberFormatter.java	Tue May 21 13:56:39 2013 +0400
+++ b/src/share/classes/javax/swing/text/NumberFormatter.java	Tue May 21 19:04:50 2013 +0400
@@ -27,6 +27,8 @@
 import java.lang.reflect.*;
 import java.text.*;
 import java.util.*;
+import sun.reflect.misc.ReflectUtil;
+import sun.swing.SwingUtilities2;
 
 /**
  * <code>NumberFormatter</code> subclasses <code>InternationalFormatter</code>
@@ -427,10 +429,12 @@
                         valueClass = value.getClass();
                     }
                     try {
+                        ReflectUtil.checkPackageAccess(valueClass);
+                        SwingUtilities2.checkAccess(valueClass.getModifiers());
                         Constructor cons = valueClass.getConstructor(
                                               new Class[] { String.class });
-
                         if (cons != null) {
+                            SwingUtilities2.checkAccess(cons.getModifiers());
                             return cons.newInstance(new Object[]{string});
                         }
                     } catch (Throwable ex) { }
--- a/src/share/classes/sun/swing/SwingLazyValue.java	Tue May 21 13:56:39 2013 +0400
+++ b/src/share/classes/sun/swing/SwingLazyValue.java	Tue May 21 19:04:50 2013 +0400
@@ -30,6 +30,7 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import javax.swing.UIDefaults;
+import sun.reflect.misc.ReflectUtil;
 
 /**
  * SwingLazyValue is a copy of ProxyLazyValue that does not snapshot the
@@ -63,7 +64,7 @@
 
     public Object createValue(final UIDefaults table) {
         try {
-            Object cl;
+            ReflectUtil.checkPackageAccess(className);
             Class<?> c = Class.forName(className, true, null);
             if (methodName != null) {
                 Class[] types = getClassArray(args);
--- a/src/share/classes/sun/swing/SwingUtilities2.java	Tue May 21 13:56:39 2013 +0400
+++ b/src/share/classes/sun/swing/SwingUtilities2.java	Tue May 21 19:04:50 2013 +0400
@@ -1301,6 +1301,19 @@
     }
 
     /**
+     * Utility method that throws SecurityException if SecurityManager is set
+     * and modifiers are not public
+     *
+     * @param modifiers a set of modifiers
+     */
+    public static void checkAccess(int modifiers) {
+        if (System.getSecurityManager() != null
+                && !Modifier.isPublic(modifiers)) {
+            throw new SecurityException("Resource is not accessible");
+        }
+    }
+
+    /**
      * Returns true if EventQueue.getCurrentEvent() has the permissions to
      * access the system clipboard and if it is allowed gesture (if
      * checkGesture true)