ObjectInputStream.java (readFields): Turn off readDataFromBlock while reading via GetField.
* java/io/ObjectInputStream.java (readFields): Turn off readDataFromBlock while reading via GetField. (GetField$1.get(String, Object)): Pass Class of default value to getField. (getField): Allow for null default values. * java/io/ObjectOutputStream.java: Fixed typo in comment. (PutField$1.put): Fixed calls of checkType in most of the put methods to pass the correct parameter. (PutField$1.put(String, Object)): Allow for null value arg. (PutField$1.write): Turn off writeDataAsBlocks while writing via PutField. * java/io/ObjectStreamClass.java (serialPersistentFields): Fixed typo in spec'ed field name. (getSerialPersistentFields): Changed spelling of method to match the correct spelling of the spec'ed field name. More serialization fixes per Mauve errors. From-SVN: r35468
This commit is contained in:
parent
a1bcc528be
commit
9b4773cbba
4 changed files with 50 additions and 17 deletions
|
@ -1,3 +1,23 @@
|
||||||
|
2000-08-03 Warren Levy <warrenl@cygnus.com>
|
||||||
|
|
||||||
|
* java/io/ObjectInputStream.java (readFields): Turn off
|
||||||
|
readDataFromBlock while reading via GetField.
|
||||||
|
(GetField$1.get(String, Object)): Pass Class of default value to
|
||||||
|
getField.
|
||||||
|
(getField): Allow for null default values.
|
||||||
|
|
||||||
|
* java/io/ObjectOutputStream.java: Fixed typo in comment.
|
||||||
|
(PutField$1.put): Fixed calls of checkType in most of the put
|
||||||
|
methods to pass the correct parameter.
|
||||||
|
(PutField$1.put(String, Object)): Allow for null value arg.
|
||||||
|
(PutField$1.write): Turn off writeDataAsBlocks while writing via
|
||||||
|
PutField.
|
||||||
|
|
||||||
|
* java/io/ObjectStreamClass.java (serialPersistentFields): Fixed
|
||||||
|
typo in spec'ed field name.
|
||||||
|
(getSerialPersistentFields): Changed spelling of method to match
|
||||||
|
the correct spelling of the spec'ed field name.
|
||||||
|
|
||||||
2000-08-03 Tom Tromey <tromey@cygnus.com>
|
2000-08-03 Tom Tromey <tromey@cygnus.com>
|
||||||
|
|
||||||
* Makefile.in: Rebuilt.
|
* Makefile.in: Rebuilt.
|
||||||
|
|
|
@ -700,9 +700,15 @@ public class ObjectInputStream extends InputStream
|
||||||
final ObjectStreamClass clazz = this.currentObjectStreamClass;
|
final ObjectStreamClass clazz = this.currentObjectStreamClass;
|
||||||
final byte[] prim_field_data = new byte[clazz.primFieldSize];
|
final byte[] prim_field_data = new byte[clazz.primFieldSize];
|
||||||
final Object[] objs = new Object[clazz.objectFieldCount];
|
final Object[] objs = new Object[clazz.objectFieldCount];
|
||||||
|
|
||||||
|
// Apparently Block data is not used with GetField as per
|
||||||
|
// empirical evidence against JDK 1.2. Also see Mauve test
|
||||||
|
// java.io.ObjectInputOutput.Test.GetPutField.
|
||||||
|
setBlockDataMode (false);
|
||||||
readFully (prim_field_data);
|
readFully (prim_field_data);
|
||||||
for (int i = 0; i < objs.length; ++ i)
|
for (int i = 0; i < objs.length; ++ i)
|
||||||
objs[i] = readObject ();
|
objs[i] = readObject ();
|
||||||
|
setBlockDataMode (true);
|
||||||
|
|
||||||
return new GetField ()
|
return new GetField ()
|
||||||
{
|
{
|
||||||
|
@ -843,7 +849,8 @@ public class ObjectInputStream extends InputStream
|
||||||
public Object get (String name, Object defvalue)
|
public Object get (String name, Object defvalue)
|
||||||
throws IOException, IllegalArgumentException
|
throws IOException, IllegalArgumentException
|
||||||
{
|
{
|
||||||
ObjectStreamField field = getField (name, null);
|
ObjectStreamField field =
|
||||||
|
getField (name, defvalue == null ? null : defvalue.getClass ());
|
||||||
|
|
||||||
if (field == null)
|
if (field == null)
|
||||||
return defvalue;
|
return defvalue;
|
||||||
|
@ -862,7 +869,7 @@ public class ObjectInputStream extends InputStream
|
||||||
Class field_type = field.getType ();
|
Class field_type = field.getType ();
|
||||||
|
|
||||||
if (type == field_type ||
|
if (type == field_type ||
|
||||||
(type != null && field_type.isPrimitive ()))
|
(type == null && ! field_type.isPrimitive ()))
|
||||||
return field;
|
return field;
|
||||||
|
|
||||||
throw new IllegalArgumentException ("Field requested is of type "
|
throw new IllegalArgumentException ("Field requested is of type "
|
||||||
|
|
|
@ -138,7 +138,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
output stream by writing out information about its class, then
|
output stream by writing out information about its class, then
|
||||||
writing out each of the objects non-transient, non-static
|
writing out each of the objects non-transient, non-static
|
||||||
fields. If any of these fields are other objects,
|
fields. If any of these fields are other objects,
|
||||||
the are written out in the same manner.
|
they are written out in the same manner.
|
||||||
|
|
||||||
This method can be overriden by a class by implementing
|
This method can be overriden by a class by implementing
|
||||||
<code>private void writeObject (ObjectOutputStream)</code>.
|
<code>private void writeObject (ObjectOutputStream)</code>.
|
||||||
|
@ -846,7 +846,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
checkType (field, 'B');
|
checkType (field, 'C');
|
||||||
int off = field.getOffset ();
|
int off = field.getOffset ();
|
||||||
prim_field_data[off++] = (byte)(value >>> 8);
|
prim_field_data[off++] = (byte)(value >>> 8);
|
||||||
prim_field_data[off] = (byte)value;
|
prim_field_data[off] = (byte)value;
|
||||||
|
@ -857,7 +857,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
checkType (field, 'B');
|
checkType (field, 'D');
|
||||||
int off = field.getOffset ();
|
int off = field.getOffset ();
|
||||||
long l_value = Double.doubleToLongBits (value);
|
long l_value = Double.doubleToLongBits (value);
|
||||||
prim_field_data[off++] = (byte)(l_value >>> 52);
|
prim_field_data[off++] = (byte)(l_value >>> 52);
|
||||||
|
@ -875,7 +875,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
checkType (field, 'B');
|
checkType (field, 'F');
|
||||||
int off = field.getOffset ();
|
int off = field.getOffset ();
|
||||||
int i_value = Float.floatToIntBits (value);
|
int i_value = Float.floatToIntBits (value);
|
||||||
prim_field_data[off++] = (byte)(i_value >>> 24);
|
prim_field_data[off++] = (byte)(i_value >>> 24);
|
||||||
|
@ -889,7 +889,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
checkType (field, 'B');
|
checkType (field, 'I');
|
||||||
int off = field.getOffset ();
|
int off = field.getOffset ();
|
||||||
prim_field_data[off++] = (byte)(value >>> 24);
|
prim_field_data[off++] = (byte)(value >>> 24);
|
||||||
prim_field_data[off++] = (byte)(value >>> 16);
|
prim_field_data[off++] = (byte)(value >>> 16);
|
||||||
|
@ -902,7 +902,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
checkType (field, 'B');
|
checkType (field, 'J');
|
||||||
int off = field.getOffset ();
|
int off = field.getOffset ();
|
||||||
prim_field_data[off++] = (byte)(value >>> 52);
|
prim_field_data[off++] = (byte)(value >>> 52);
|
||||||
prim_field_data[off++] = (byte)(value >>> 48);
|
prim_field_data[off++] = (byte)(value >>> 48);
|
||||||
|
@ -919,7 +919,7 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
checkType (field, 'B');
|
checkType (field, 'S');
|
||||||
int off = field.getOffset ();
|
int off = field.getOffset ();
|
||||||
prim_field_data[off++] = (byte)(value >>> 8);
|
prim_field_data[off++] = (byte)(value >>> 8);
|
||||||
prim_field_data[off] = (byte)value;
|
prim_field_data[off] = (byte)value;
|
||||||
|
@ -930,16 +930,22 @@ public class ObjectOutputStream extends OutputStream
|
||||||
{
|
{
|
||||||
ObjectStreamField field
|
ObjectStreamField field
|
||||||
= currentObjectStreamClass.getField (name);
|
= currentObjectStreamClass.getField (name);
|
||||||
if (! field.getType ().isAssignableFrom (value.getClass ()))
|
if (value != null &&
|
||||||
|
! field.getType ().isAssignableFrom (value.getClass ()))
|
||||||
throw new IllegalArgumentException ();
|
throw new IllegalArgumentException ();
|
||||||
objs[field.getOffset ()] = value;
|
objs[field.getOffset ()] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write (ObjectOutput out) throws IOException
|
public void write (ObjectOutput out) throws IOException
|
||||||
{
|
{
|
||||||
|
// Apparently Block data is not used with PutField as per
|
||||||
|
// empirical evidence against JDK 1.2. Also see Mauve test
|
||||||
|
// java.io.ObjectInputOutput.Test.GetPutField.
|
||||||
|
setBlockDataMode (false);
|
||||||
out.write (prim_field_data);
|
out.write (prim_field_data);
|
||||||
for (int i = 0; i < objs.length; ++ i)
|
for (int i = 0; i < objs.length; ++ i)
|
||||||
out.writeObject (objs[i]);
|
out.writeObject (objs[i]);
|
||||||
|
setBlockDataMode (true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkType (ObjectStreamField field, char type)
|
private void checkType (ObjectStreamField field, char type)
|
||||||
|
|
|
@ -350,15 +350,15 @@ public class ObjectStreamClass implements Serializable
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Field serialPersistantFields
|
Field serialPersistentFields
|
||||||
= cl.getDeclaredField ("serialPersistantFields");
|
= cl.getDeclaredField ("serialPersistentFields");
|
||||||
int modifiers = serialPersistantFields.getModifiers ();
|
int modifiers = serialPersistentFields.getModifiers ();
|
||||||
|
|
||||||
if (Modifier.isStatic (modifiers)
|
if (Modifier.isStatic (modifiers)
|
||||||
&& Modifier.isFinal (modifiers)
|
&& Modifier.isFinal (modifiers)
|
||||||
&& Modifier.isPrivate (modifiers))
|
&& Modifier.isPrivate (modifiers))
|
||||||
{
|
{
|
||||||
fields = getSerialPersistantFields (cl);
|
fields = getSerialPersistentFields (cl);
|
||||||
Arrays.sort (fields);
|
Arrays.sort (fields);
|
||||||
calculateOffsets ();
|
calculateOffsets ();
|
||||||
return;
|
return;
|
||||||
|
@ -569,15 +569,15 @@ public class ObjectStreamClass implements Serializable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the value of CLAZZ's private static final field named
|
// Returns the value of CLAZZ's private static final field named
|
||||||
// `serialPersistantFields'.
|
// `serialPersistentFields'.
|
||||||
private ObjectStreamField[] getSerialPersistantFields (Class clazz)
|
private ObjectStreamField[] getSerialPersistentFields (Class clazz)
|
||||||
{
|
{
|
||||||
ObjectStreamField[] o = null;
|
ObjectStreamField[] o = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Use getDeclaredField rather than getField for the same reason
|
// Use getDeclaredField rather than getField for the same reason
|
||||||
// as above in getDefinedSUID.
|
// as above in getDefinedSUID.
|
||||||
Field f = clazz.getDeclaredField ("getSerialPersistantFields");
|
Field f = clazz.getDeclaredField ("getSerialPersistentFields");
|
||||||
o = (ObjectStreamField[])f.get (null);
|
o = (ObjectStreamField[])f.get (null);
|
||||||
}
|
}
|
||||||
catch (java.lang.NoSuchFieldException e)
|
catch (java.lang.NoSuchFieldException e)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue