Commit 9b2b6c0f by Jeroen Frijters Committed by Mark Wielaard

Proxy.java (getPackage, [...]): Fixed handling of default package.

2004-09-25  Jeroen Frijters  <jeroen@frijters.net>

       * java/lang/reflect/Proxy.java (getPackage, ClassFactory): Fixed
       handling of default package. (generate): Removed confused comments
       and code about making Method and Field accessible.

From-SVN: r88109
parent c1f042f8
2004-09-25 Jeroen Frijters <jeroen@frijters.net>
* java/lang/reflect/Proxy.java (getPackage, ClassFactory): Fixed
handling of default package. (generate): Removed confused comments
and code about making Method and Field accessible.
2004-09-25 Tom Tromey <tromey@redhat.com> 2004-09-25 Tom Tromey <tromey@redhat.com>
PR java/17500: PR java/17500:
......
...@@ -722,8 +722,8 @@ public class Proxy implements Serializable ...@@ -722,8 +722,8 @@ public class Proxy implements Serializable
private static final class ProxyData private static final class ProxyData
{ {
/** /**
* The package this class is in. Possibly null, meaning the unnamed * The package this class is in *including the trailing dot* or "" for
* package. * the unnamed (aka default) package.
*/ */
String pack; String pack;
...@@ -769,18 +769,17 @@ public class Proxy implements Serializable ...@@ -769,18 +769,17 @@ public class Proxy implements Serializable
} }
/** /**
* Return the name of a package given the name of a class. * Return the name of a package (including the trailing dot)
* Returns null if no package. We use this in preference to * given the name of a class.
* Returns "" if no package. We use this in preference to
* using Class.getPackage() to avoid problems with ClassLoaders * using Class.getPackage() to avoid problems with ClassLoaders
* that don't set the package. * that don't set the package.
*/ */
static String getPackage(Class k) private static String getPackage(Class k)
{ {
String name = k.getName(); String name = k.getName();
int idx = name.lastIndexOf('.'); int idx = name.lastIndexOf('.');
if (idx >= 0) return name.substring(0, idx + 1);
return name.substring(0, idx);
return null;
} }
/** /**
...@@ -961,8 +960,7 @@ public class Proxy implements Serializable ...@@ -961,8 +960,7 @@ public class Proxy implements Serializable
// access_flags // access_flags
putU2(Modifier.SUPER | Modifier.FINAL | Modifier.PUBLIC); putU2(Modifier.SUPER | Modifier.FINAL | Modifier.PUBLIC);
// this_class // this_class
qualName = ((data.pack == null ? "" : data.pack + '.') qualName = (data.pack + "$Proxy" + data.id);
+ "$Proxy" + data.id);
putU2(classInfo(TypeSignature.getEncodingOfClass(qualName, false))); putU2(classInfo(TypeSignature.getEncodingOfClass(qualName, false)));
// super_class // super_class
putU2(classInfo("java/lang/reflect/Proxy")); putU2(classInfo("java/lang/reflect/Proxy"));
...@@ -1325,34 +1323,26 @@ public class Proxy implements Serializable ...@@ -1325,34 +1323,26 @@ public class Proxy implements Serializable
try try
{ {
// XXX Do we require more native support here?
Class vmClassLoader = Class.forName("java.lang.VMClassLoader"); Class vmClassLoader = Class.forName("java.lang.VMClassLoader");
Class[] types = {ClassLoader.class, String.class, Class[] types = {ClassLoader.class, String.class,
byte[].class, int.class, int.class, byte[].class, int.class, int.class,
ProtectionDomain.class }; ProtectionDomain.class };
Method m = vmClassLoader.getDeclaredMethod("defineClass", types); Method m = vmClassLoader.getDeclaredMethod("defineClass", types);
// We can bypass the security check of setAccessible(true), since
// Bypass the security check of setAccessible(true), since this // we're in the same package.
// is trusted code. But note the comment above about the security
// risk of doing this outside a synchronized block.
m.flag = true; m.flag = true;
Object[] args = {loader, qualName, bytecode, new Integer(0), Object[] args = {loader, qualName, bytecode, new Integer(0),
new Integer(bytecode.length), new Integer(bytecode.length),
Object.class.getProtectionDomain() }; Object.class.getProtectionDomain() };
Class clazz = (Class) m.invoke(null, args); Class clazz = (Class) m.invoke(null, args);
m.flag = false;
// Finally, initialize the m field of the proxy class, before // Finally, initialize the m field of the proxy class, before
// returning it. // returning it.
// No security risk here, since clazz has not been exposed yet,
// so user code cannot grab the same reflection object.
Field f = clazz.getDeclaredField("m"); Field f = clazz.getDeclaredField("m");
f.flag = true; f.flag = true;
// we can share the array, because it is not publicized // we can share the array, because it is not publicized
f.set(null, methods); f.set(null, methods);
f.flag = false;
return clazz; return clazz;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment