[jboss-jira] [JBoss JIRA] Created: (JBSER-120) Can't add field to class as the Java Serialization says is compatible

Tom Saulpaugh (JIRA) jira-events at lists.jboss.org
Mon Mar 29 14:08:37 EDT 2010


Can't add field to class as the Java Serialization says is compatible
---------------------------------------------------------------------

                 Key: JBSER-120
                 URL: https://jira.jboss.org/jira/browse/JBSER-120
             Project: JBoss Serialization
          Issue Type: Bug
    Affects Versions: 1.0.3 GA
         Environment: WIndows 2003 server 64-bit
            Reporter: Tom Saulpaugh
            Assignee: Clebert Suconic
             Fix For: 1.1.0 Beta


I traced through this in jboss-serialization and it appears to be a basic coding bug.  Look at this code in StreamingClass.readStream(), which includes the exception being thrown:

            short numberofFields=inp.readShort();
            keyfields[slotIndex] = new short[numberofFields];
            
            ClassMetadataField fields[] = slots[slotIndex].getFields();
            if (numberofFields>fields.length)
            {
                throw new IOException("Current classpath has lesser fields on " + className + " than its original version");
            }
            for (short fieldIndex=0;fieldIndex<fields.length;fieldIndex++)
            {
                long hashfield = inp.readLong();
                ClassMetadataField fieldOnHash = slots[slotIndex].getField(hashfield);
                if (fieldOnHash==null)
                {
                    throw new IOException ("Field hash " + fieldOnHash + " is not available on current classPath for class " + className);
                }
                keyfields[slotIndex][fieldIndex] = fieldOnHash.getOrder();
            }

Note that there are numberOfFields fields on the serialized prior version of the object, while there are fields.length fields in the new version of the class being deserialized to.  The code reads the serialized fields and looks up the correspondent fields on the new class by hash.

However, note that it reads fields.length fields from the file instead of numberofFields fields!!!

That is the problem.  It reads a long from the file that is not even a hash code of a field and so can't find it in the hash array, whence the null.

This really does mean that the latest version of JBoss serialization has a bug that causes it to fail to handle field additions on new versions of classes.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the jboss-jira mailing list