ObjectInputStream.java (readObject): Delegate instantation of Externalizable classes to ObjectStreamClass.
2004-09-24 Jeroen Frijters <jeroen@frijters.net> * java/io/ObjectInputStream.java (readObject): Delegate instantation of Externalizable classes to ObjectStreamClass. * java/io/ObjectStreamClass.java (newInstance): New method to instantiate Externalizable (while ignoring the accessibility of the constructor). (constructor): New field to cache the constructor. From-SVN: r88019
This commit is contained in:
parent
8ac4bd3706
commit
73eb130916
|
@ -1,3 +1,11 @@
|
||||||
|
2004-09-24 Jeroen Frijters <jeroen@frijters.net>
|
||||||
|
|
||||||
|
* java/io/ObjectInputStream.java (readObject): Delegate instantation
|
||||||
|
of Externalizable classes to ObjectStreamClass.
|
||||||
|
* java/io/ObjectStreamClass.java (newInstance): New method to
|
||||||
|
instantiate Externalizable (while ignoring the accessibility of
|
||||||
|
the constructor). (constructor): New field to cache the constructor.
|
||||||
|
|
||||||
2004-09-24 Mark Wielaard <mark@klomp.org>
|
2004-09-24 Mark Wielaard <mark@klomp.org>
|
||||||
|
|
||||||
* java/net/URL.java (systemClassLoader): New static field.
|
* java/net/URL.java (systemClassLoader): New static field.
|
||||||
|
|
|
@ -291,29 +291,7 @@ public class ObjectInputStream extends InputStream
|
||||||
|
|
||||||
if (osc.realClassIsExternalizable)
|
if (osc.realClassIsExternalizable)
|
||||||
{
|
{
|
||||||
Externalizable obj = null;
|
Externalizable obj = osc.newInstance();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
obj = (Externalizable)clazz.newInstance();
|
|
||||||
}
|
|
||||||
catch (InstantiationException e)
|
|
||||||
{
|
|
||||||
throw new ClassNotFoundException
|
|
||||||
("Instance of " + clazz + " could not be created");
|
|
||||||
}
|
|
||||||
catch (IllegalAccessException e)
|
|
||||||
{
|
|
||||||
throw new ClassNotFoundException
|
|
||||||
("Instance of " + clazz + " could not be created because class or "
|
|
||||||
+ "zero-argument constructor is not accessible");
|
|
||||||
}
|
|
||||||
catch (NoSuchMethodError e)
|
|
||||||
{
|
|
||||||
throw new ClassNotFoundException
|
|
||||||
("Instance of " + clazz
|
|
||||||
+ " could not be created because zero-argument constructor is not defined");
|
|
||||||
}
|
|
||||||
|
|
||||||
int handle = assignNewHandle(obj);
|
int handle = assignNewHandle(obj);
|
||||||
|
|
||||||
|
|
|
@ -811,6 +811,54 @@ outer:
|
||||||
return fieldsArray;
|
return fieldsArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a new instance of the Class this ObjectStreamClass corresponds
|
||||||
|
* to.
|
||||||
|
* Note that this should only be used for Externalizable classes.
|
||||||
|
*
|
||||||
|
* @return A new instance.
|
||||||
|
*/
|
||||||
|
Externalizable newInstance() throws InvalidClassException
|
||||||
|
{
|
||||||
|
synchronized(this)
|
||||||
|
{
|
||||||
|
if (constructor == null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
final Constructor c = clazz.getConstructor(new Class[0]);
|
||||||
|
|
||||||
|
AccessController.doPrivileged(new PrivilegedAction()
|
||||||
|
{
|
||||||
|
public Object run()
|
||||||
|
{
|
||||||
|
c.setAccessible(true);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
constructor = c;
|
||||||
|
}
|
||||||
|
catch(NoSuchMethodException x)
|
||||||
|
{
|
||||||
|
throw new InvalidClassException(clazz.getName(),
|
||||||
|
"No public zero-argument constructor");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return (Externalizable)constructor.newInstance(null);
|
||||||
|
}
|
||||||
|
catch(Throwable t)
|
||||||
|
{
|
||||||
|
throw (InvalidClassException)
|
||||||
|
new InvalidClassException(clazz.getName(),
|
||||||
|
"Unable to instantiate").initCause(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static final ObjectStreamField[] NO_FIELDS = {};
|
public static final ObjectStreamField[] NO_FIELDS = {};
|
||||||
|
|
||||||
private static Hashtable classLookupTable = new Hashtable();
|
private static Hashtable classLookupTable = new Hashtable();
|
||||||
|
@ -840,6 +888,7 @@ outer:
|
||||||
boolean realClassIsExternalizable;
|
boolean realClassIsExternalizable;
|
||||||
ObjectStreamField[] fieldMapping;
|
ObjectStreamField[] fieldMapping;
|
||||||
Class firstNonSerializableParent;
|
Class firstNonSerializableParent;
|
||||||
|
private Constructor constructor; // default constructor for Externalizable
|
||||||
|
|
||||||
boolean isProxyClass = false;
|
boolean isProxyClass = false;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue