diff options
author | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-15 17:34:11 +0000 |
---|---|---|
committer | aph <aph@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-15 17:34:11 +0000 |
commit | 5619747e763aff61b269f6f1ebc593fc42d2b446 (patch) | |
tree | ba3472b781df2a031293e8710ab24a47403dabba /libjava/java/io | |
parent | c817aae96f3c454780ddd58549e43e57b3b3b8af (diff) | |
download | gcc-5619747e763aff61b269f6f1ebc593fc42d2b446.tar.gz |
2005-11-15 Andrew Haley <aph@redhat.com>
* Merge from Classpath head:
2005-09-16 Andrew Haley <aph@redhat.com>
* java/io/ObjectStreamClass.java (findAccessibleMethod): Allow
protected readResolve(). Rewrite accessibility check.
2005-07-07 Jeroen Frijters <jeroen@frijters.net>
* java/io/ObjectStreamClass.java
(findAccessibleMethod): Added code to make method accessible.
2005-07-03 Daniel Bonniot <bonniot@users.sf.net>
* java/io/ObjectStreamClass.java (inSamePackage): New private method.
(findAccessibleMethod): Likewise.
(cacheMethods): Lookup readResolve and writeReplace using the new
findAccessibleMethod().
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107029 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java/io')
-rw-r--r-- | libjava/java/io/ObjectStreamClass.java | 56 |
1 files changed, 52 insertions, 4 deletions
diff --git a/libjava/java/io/ObjectStreamClass.java b/libjava/java/io/ObjectStreamClass.java index a292f0b5ffc..975dbfc66d0 100644 --- a/libjava/java/io/ObjectStreamClass.java +++ b/libjava/java/io/ObjectStreamClass.java @@ -486,19 +486,67 @@ outer: return null; } + private static boolean inSamePackage(Class c1, Class c2) + { + String name1 = c1.getName(); + String name2 = c2.getName(); + + int id1 = name1.lastIndexOf('.'); + int id2 = name2.lastIndexOf('.'); + + // Handle the default package + if (id1 == -1 || id2 == -1) + return id1 == id2; + + String package1 = name1.substring(0, id1); + String package2 = name2.substring(0, id2); + + return package1.equals(package2); + } + + final static Class[] noArgs = new Class[0]; + + private static Method findAccessibleMethod(String name, Class from) + { + for (Class c = from; c != null; c = c.getSuperclass()) + { + try + { + Method res = c.getDeclaredMethod(name, noArgs); + int mods = res.getModifiers(); + + if (c == from + || Modifier.isProtected(mods) + || Modifier.isPublic(mods) + || (! Modifier.isPrivate(mods) && inSamePackage(c, from))) + { + AccessController.doPrivileged(new SetAccessibleAction(res)); + return res; + } + } + catch (NoSuchMethodException e) + { + } + } + + return null; + } + private void cacheMethods() { Method[] methods = forClass().getDeclaredMethods(); + readObjectMethod = findMethod(methods, "readObject", new Class[] { ObjectInputStream.class }, Void.TYPE, true); writeObjectMethod = findMethod(methods, "writeObject", new Class[] { ObjectOutputStream.class }, Void.TYPE, true); - readResolveMethod = findMethod(methods, "readResolve", - new Class[0], Object.class, false); - writeReplaceMethod = findMethod(methods, "writeReplace", - new Class[0], Object.class, false); + + // readResolve and writeReplace can be in parent classes, as long as they + // are accessible from this class. + readResolveMethod = findAccessibleMethod("readResolve", forClass()); + writeReplaceMethod = findAccessibleMethod("writeReplace", forClass()); } private ObjectStreamClass(Class cl) |