Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4387368
Votes 0
Synopsis Invalid serialPersistentFields field name causes NullPointerException
Category java:serialization
Reported Against 1.3
Release Fixed 1.4(merlin-beta)
State 10-Fix Delivered, Verified, bug
Priority: 3-Medium
Related Bugs
Submit Date 08-NOV-2000
Description




8 Nov 2000,  xxxxx@xxxxx  -- see also # 4337857, 4334265, 4065313
------------------------
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

I believe the following invalid ObjectStreamField definition should
result in the program failing with a WriteAbortedException or similar
exception rather than crashing with a NullPointerException.

import java.io.*;

class X implements Serializable
{
    private static final ObjectStreamField[] serialPersistentFields = {
        new ObjectStreamField("int", int.class),
    };
    private int i = 1;

    public String toString()
    {
        return "{i="+i+"}";
    }

    public static void main(String[] args) throws Exception
    {
        X x = new X();
        FileOutputStream fos = new FileOutputStream("x.ser");
        ObjectOutputStream oos = new ObjectOutputStream(fos);
        oos.writeObject(x);
        oos.close();
        System.out.println("Wrote: "+x);
        System.exit(0);
    }
}

bash-2.04$ java -cp . X
Exception in thread "main" java.lang.NullPointerException
        at java.io.ObjectOutputStream.getPrimitiveFieldValues(Native Method)
        at java.io.ObjectOutputStream.outputClassFields
(ObjectOutputStream.java:1826)
        at java.io.ObjectOutputStream.defaultWriteObject
(ObjectOutputStream.java:480)
        at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1214)

        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
        at X.main(X.java:20)
bash-2.04$
(Review ID: 111078) 
======================================================================
Work Around




Don't screw up the serialPersistentFields definition
======================================================================
Evaluation
This is a bug; as stated in the description, some exception other than
NullPointerException should be thrown (most likely an IOException subclass).
Note that the NullPointerException does not occur if the PutField API is
used to set the outgoing field values, which is the intended usage in cases
where serialPersistentFields is used to define serializable fields that don't
exist in the class.

 xxxxx@xxxxx  2000-11-08

ObjectOutputStream.writeObject() now throws an InvalidClassException if
an attempt is made to write an object via default serialization which
defines "unmatched" serializable fields.

 xxxxx@xxxxx  2001-03-21
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang