提交 ec70c551 编写于 作者: M malenkov

8012071: Better Building of Beans

Reviewed-by: art, skoivu
上级 07c61882
...@@ -42,6 +42,8 @@ import java.io.ObjectInputStream; ...@@ -42,6 +42,8 @@ import java.io.ObjectInputStream;
import java.io.ObjectStreamClass; import java.io.ObjectStreamClass;
import java.io.StreamCorruptedException; import java.io.StreamCorruptedException;
import java.lang.reflect.Modifier;
import java.net.URL; import java.net.URL;
import java.security.AccessController; import java.security.AccessController;
...@@ -222,6 +224,10 @@ public class Beans { ...@@ -222,6 +224,10 @@ public class Beans {
throw ex; throw ex;
} }
if (!Modifier.isPublic(cl.getModifiers())) {
throw new ClassNotFoundException("" + cl + " : no public access");
}
/* /*
* Try to instantiate the class. * Try to instantiate the class.
*/ */
......
...@@ -221,6 +221,9 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { ...@@ -221,6 +221,9 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate {
// Write out the properties of this instance. // Write out the properties of this instance.
private void initBean(Class<?> type, Object oldInstance, Object newInstance, Encoder out) { private void initBean(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
for (Field field : type.getFields()) { for (Field field : type.getFields()) {
if (!ReflectUtil.isPackageAccessible(field.getDeclaringClass())) {
continue;
}
int mod = field.getModifiers(); int mod = field.getModifiers();
if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) { if (Modifier.isFinal(mod) || Modifier.isStatic(mod) || Modifier.isTransient(mod)) {
continue; continue;
......
...@@ -42,6 +42,7 @@ import java.lang.reflect.Array; ...@@ -42,6 +42,7 @@ import java.lang.reflect.Array;
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.security.AccessController; import java.security.AccessController;
...@@ -56,7 +57,7 @@ import javax.swing.plaf.ColorUIResource; ...@@ -56,7 +57,7 @@ import javax.swing.plaf.ColorUIResource;
import sun.swing.PrintColorUIResource; 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 * Like the <code>Intropector</code>, the <code>MetaData</code> class
...@@ -850,6 +851,7 @@ static final class java_awt_AWTKeyStroke_PersistenceDelegate extends Persistence ...@@ -850,6 +851,7 @@ static final class java_awt_AWTKeyStroke_PersistenceDelegate extends Persistence
static class StaticFieldsPersistenceDelegate extends PersistenceDelegate { static class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
protected void installFields(Encoder out, Class<?> cls) { protected void installFields(Encoder out, Class<?> cls) {
if (Modifier.isPublic(cls.getModifiers()) && isPackageAccessible(cls)) {
Field fields[] = cls.getFields(); Field fields[] = cls.getFields();
for(int i = 0; i < fields.length; i++) { for(int i = 0; i < fields.length; i++) {
Field field = fields[i]; Field field = fields[i];
...@@ -860,6 +862,7 @@ static class StaticFieldsPersistenceDelegate extends PersistenceDelegate { ...@@ -860,6 +862,7 @@ static class StaticFieldsPersistenceDelegate extends PersistenceDelegate {
} }
} }
} }
}
protected Expression instantiate(Object oldInstance, Encoder out) { protected Expression instantiate(Object oldInstance, Encoder out) {
throw new RuntimeException("Unrecognized instance: " + oldInstance); throw new RuntimeException("Unrecognized instance: " + oldInstance);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册