[kaffe] CVS kaffe (guilhem): More serialization fixes.
Kaffe CVS
cvs-commits at kaffe.org
Thu Feb 26 09:31:02 PST 2004
PatchSet 4464
Date: 2004/02/26 17:08:08
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
More serialization fixes.
* java/io/ObjectInputStream.java
(readClassDescriptor): Keep elements of the mapping non null.
(checkTypeConsistency): New method.
(readFields): Fixed main loop and base logic. Small reindentation.
* java/io/ObjectStreamField.java
(lookupField): New method to update the field reference.
(checkFieldType): New method.
* java/io/ObjectStreamClass.java
(setClass, setFields): Call lookupField when building the field
database. Check the real field type.
Members:
ChangeLog:1.2044->1.2045
libraries/javalib/java/io/ObjectInputStream.java:1.33->1.34
libraries/javalib/java/io/ObjectStreamClass.java:1.20->1.21
libraries/javalib/java/io/ObjectStreamField.java:1.7->1.8
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2044 kaffe/ChangeLog:1.2045
--- kaffe/ChangeLog:1.2044 Wed Feb 25 19:28:24 2004
+++ kaffe/ChangeLog Thu Feb 26 17:08:08 2004
@@ -1,3 +1,18 @@
+2004-02-26 Guilhem Lavaux <guilhem at kaffe.org>
+
+ * java/io/ObjectInputStream.java
+ (readClassDescriptor): Keep elements of the mapping non null.
+ (checkTypeConsistency): New method.
+ (readFields): Fixed main loop and base logic. Small reindentation.
+
+ * java/io/ObjectStreamField.java
+ (lookupField): New method to update the field reference.
+ (checkFieldType): New method.
+
+ * java/io/ObjectStreamClass.java
+ (setClass, setFields): Call lookupField when building the field
+ database. Check the real field type.
+
2004-02-24 Dalibor Topic <robilad at kaffe.org>
Resynced with GNU Classpath
Index: kaffe/libraries/javalib/java/io/ObjectInputStream.java
diff -u kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.33 kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.34
--- kaffe/libraries/javalib/java/io/ObjectInputStream.java:1.33 Sun Feb 22 08:33:10 2004
+++ kaffe/libraries/javalib/java/io/ObjectInputStream.java Thu Feb 26 17:08:11 2004
@@ -412,6 +412,65 @@
}
/**
+ * This method makes a partial check of types for the fields
+ * contained given in arguments. It checks primitive types of
+ * fields1 against non primitive types of fields2. This method
+ * assumes the two lists has already been sorted according to
+ * the Java specification.
+ *
+ * @param name Name of the class owning the given fields.
+ * @param fields1 First list to check.
+ * @param fields2 Second list to check.
+ * @throws InvalidClassException if a field in fields1, which has a primitive type, is a present
+ * in the non primitive part in fields2.
+ */
+ private void checkTypeConsistency(String name, ObjectStreamField[] fields1, ObjectStreamField[] fields2)
+ throws InvalidClassException
+ {
+ int nonPrimitive = 0;
+
+ for (nonPrimitive = 0;
+ nonPrimitive < fields1.length
+ && fields1[nonPrimitive].isPrimitive(); nonPrimitive++)
+ {
+ }
+
+ if (nonPrimitive == fields1.length)
+ return;
+
+ int i = 0;
+ ObjectStreamField f1;
+ ObjectStreamField f2;
+
+ while (i < fields2.length
+ && nonPrimitive < fields1.length)
+ {
+ f1 = fields1[nonPrimitive];
+ f2 = fields2[i];
+
+ if (!f2.isPrimitive())
+ break;
+
+ int compVal = f1.getName().compareTo (f2.getName());
+
+ if (compVal < 0)
+ {
+ nonPrimitive++;
+ }
+ else if (compVal > 0)
+ {
+ i++;
+ }
+ else
+ {
+ throw new InvalidClassException
+ ("invalid field type for " + f2.getName() +
+ " in class " + name);
+ }
+ }
+ }
+
+ /**
* This method reads a class descriptor from the real input stream
* and use these data to create a new instance of ObjectStreamClass.
* Fields are sorted and ordered for the real read which occurs for
@@ -496,6 +555,15 @@
int real_idx = 0;
int map_idx = 0;
+ /*
+ * Check that there is no type inconsistencies between the lists.
+ * A special checking must be done for the two groups: primitive types and
+ * not primitive types.
+ */
+ checkTypeConsistency(name, real_fields, stream_fields);
+ checkTypeConsistency(name, stream_fields, real_fields);
+
+
while (stream_idx < stream_fields.length
|| real_idx < real_fields.length)
{
@@ -513,7 +581,7 @@
else
{
int comp_val =
- real_fields[real_idx].getName().compareTo (stream_fields[stream_idx].getName());
+ real_fields[real_idx].compareTo (stream_fields[stream_idx]);
if (comp_val < 0)
{
@@ -1671,8 +1739,8 @@
{
Object value =
read_value ? readObject() : null;
- if (set_value && stream_field != null)
- real_field.setObjectField(obj, stream_field.getTypeString(), value);
+ if (set_value)
+ real_field.setObjectField(obj, value);
break;
}
default:
Index: kaffe/libraries/javalib/java/io/ObjectStreamClass.java
diff -u kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.20 kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.21
--- kaffe/libraries/javalib/java/io/ObjectStreamClass.java:1.20 Sun Feb 22 08:33:10 2004
+++ kaffe/libraries/javalib/java/io/ObjectStreamClass.java Thu Feb 26 17:08:11 2004
@@ -327,7 +327,7 @@
i = 0; j = 0; k = 0;
while (i < fields.length && j < exportedFields.length)
{
- int comp = fields[i].getName().compareTo(exportedFields[j].getName());
+ int comp = fields[i].compareTo(exportedFields[j]);
if (comp < 0)
{
@@ -344,11 +344,27 @@
newFieldList[k] = exportedFields[j];
newFieldList[k].setPersistent(true);
newFieldList[k].setToSet(false);
- newFieldList[k].lookupField(clazz);
+ try
+ {
+ newFieldList[k].lookupField(clazz);
+ newFieldList[k].checkFieldType();
+ }
+ catch (NoSuchFieldException _)
+ {
+ }
j++;
}
else
{
+ try
+ {
+ exportedFields[j].lookupField(clazz);
+ exportedFields[j].checkFieldType();
+ }
+ catch (NoSuchFieldException _)
+ {
+ }
+
if (!fields[i].getType().equals(exportedFields[j].getType()))
throw new InvalidClassException
("serialPersistentFields must be compatible with" +
Index: kaffe/libraries/javalib/java/io/ObjectStreamField.java
diff -u kaffe/libraries/javalib/java/io/ObjectStreamField.java:1.7 kaffe/libraries/javalib/java/io/ObjectStreamField.java:1.8
--- kaffe/libraries/javalib/java/io/ObjectStreamField.java:1.7 Sun Feb 22 08:33:10 2004
+++ kaffe/libraries/javalib/java/io/ObjectStreamField.java Thu Feb 26 17:08:11 2004
@@ -329,162 +329,128 @@
this.field = f;
}
+ /**
+ * This method check whether the field described by this
+ * instance of ObjectStreamField is compatible with the
+ * actual implementation of this field.
+ *
+ * @throws NullPointerException if this field does not exist
+ * in the real class.
+ * @throws InvalidClassException if the types are incompatible.
+ */
+ void checkFieldType() throws InvalidClassException
+ {
+ Class ftype = field.getType();
+
+ if (!ftype.isAssignableFrom(type))
+ throw new InvalidClassException
+ ("invalid field type for " + name +
+ " in class " + field.getDeclaringClass());
+ }
+
public String toString ()
{
return "ObjectStreamField< " + type + " " + name + " >";
}
- /*
- * These methods set the required field in the class instance obj.
- * They may throw NullPointerException if the field does not really exist.
- */
-
- final void setBooleanField(Object obj, boolean val) throws IOException
+ final void setBooleanField(Object obj, boolean val)
{
try
{
field.setBoolean(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setByteField(Object obj, byte val) throws IOException
+ final void setByteField(Object obj, byte val)
{
try
{
field.setByte(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setCharField(Object obj, char val) throws IOException
+ final void setCharField(Object obj, char val)
{
try
{
field.setChar(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setShortField(Object obj, short val) throws IOException
+ final void setShortField(Object obj, short val)
{
try
{
field.setShort(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setIntField(Object obj, int val) throws IOException
+ final void setIntField(Object obj, int val)
{
try
{
field.setInt(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
- catch (Exception _)
- {
- }
}
- final void setLongField(Object obj, long val) throws IOException
+ final void setLongField(Object obj, long val)
{
try
{
field.setLong(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setFloatField(Object obj, float val) throws IOException
+ final void setFloatField(Object obj, float val)
{
try
{
field.setFloat(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setDoubleField(Object obj, double val) throws IOException
+ final void setDoubleField(Object obj, double val)
{
try
{
field.setDouble(obj, val);
}
- catch (IllegalArgumentException _)
- {
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
- }
catch(IllegalAccessException x)
{
throw new InternalError(x.getMessage());
}
}
- final void setObjectField(Object obj, String valtype, Object val) throws IOException
- {
- if (valtype == null ||
- !typename.equals(valtype))
- throw new InvalidClassException("incompatible field type for " +
- obj.getClass().getName() + "." + name);
-
+ final void setObjectField(Object obj, Object val)
+ {
try
{
field.set(obj, val);
More information about the kaffe
mailing list