changeset 6646:3db0c3b7e851

8012071: Better Building of Beans Reviewed-by: art, skoivu
author malenkov
date Mon, 20 May 2013 17:55:49 +0400
parents 3c60dc9b19b9
children 12dfdb90cc90
files src/share/classes/java/beans/Beans.java src/share/classes/java/beans/DefaultPersistenceDelegate.java src/share/classes/java/beans/MetaData.java
diffstat 3 files changed, 20 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/beans/Beans.java	Fri May 17 14:29:51 2013 -0700
+++ b/src/share/classes/java/beans/Beans.java	Mon May 20 17:55:49 2013 +0400
@@ -42,6 +42,8 @@
 import java.io.ObjectStreamClass;
 import java.io.StreamCorruptedException;
 
+import java.lang.reflect.Modifier;
+
 import java.net.URL;
 
 import java.security.AccessController;
@@ -222,6 +224,10 @@
                 throw ex;
             }
 
+            if (!Modifier.isPublic(cl.getModifiers())) {
+                throw new ClassNotFoundException("" + cl + " : no public access");
+            }
+
             /*
              * Try to instantiate the class.
              */
--- a/src/share/classes/java/beans/DefaultPersistenceDelegate.java	Fri May 17 14:29:51 2013 -0700
+++ b/src/share/classes/java/beans/DefaultPersistenceDelegate.java	Mon May 20 17:55:49 2013 +0400
@@ -220,6 +220,9 @@
     // Write out the properties of this instance.
     private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) {
         for (Field field : type.getFields()) {
+            if (!ReflectUtil.isPackageAccessible(field.getDeclaringClass())) {
+                continue;
+            }
             int mod = field.getModifiers();
             if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
                 continue;
--- a/src/share/classes/java/beans/MetaData.java	Fri May 17 14:29:51 2013 -0700
+++ b/src/share/classes/java/beans/MetaData.java	Mon May 20 17:55:49 2013 +0400
@@ -42,6 +42,7 @@
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.InvocationTargetException;
 
 import java.security.AccessController;
@@ -56,7 +57,7 @@
 
 import sun.swing.PrintColorUIResource;
 
-import java.util.Objects;
+import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
 
 /*
  * Like the <code>Intropector</code>, the <code>MetaData</code> class
@@ -845,13 +846,15 @@
 
 class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
     protected void installFields(Encoder out, Class<?> cls) {
-        Field fields[] = cls.getFields();
-        for(int i = 0; i < fields.length; i++) {
-            Field field = fields[i];
-            // Don't install primitives, their identity will not be preserved
-            // by wrapping.
-            if (Object.class.isAssignableFrom(field.getType())) {
-                out.writeExpression(new Expression(field, "get", new Object[]{null}));
+        if (Modifier.isPublic(cls.getModifiers()) && isPackageAccessible(cls)) {
+            Field fields[] = cls.getFields();
+            for(int i = 0; i < fields.length; i++) {
+                Field field = fields[i];
+                // Don't install primitives, their identity will not be preserved
+                // by wrapping.
+                if (Object.class.isAssignableFrom(field.getType())) {
+                    out.writeExpression(new Expression(field, "get", new Object[]{null}));
+                }
             }
         }
     }