Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4387368

Invalid serialPersistentFields field name causes NullPointerException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 1.3.0
    • core-libs
    • beta
    • generic
    • generic
    • Verified



      Name: krC82822 Date: 11/08/2000


      8 Nov 2000, eval1127@eng -- 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)
      ======================================================================

            mwarressunw Michael Warres (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: