[multiple changes]
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(). From-SVN: r107029
This commit is contained in:
parent
5ec0b2e592
commit
2dfedb225b
@ -1,3 +1,24 @@
|
||||
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().
|
||||
|
||||
2005-11-14 Mohan Embar <gnustuff@thisiscool.com>
|
||||
|
||||
* java/net/natVMNetworkInterfaceWin32.cc: Include
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user