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

java.awt.Color can not be serialized

    XMLWordPrintable

Details

    • 2d
    • beta
    • sparc
    • solaris_2.6

    Description



      Name: ooR10001 Date: 04/13/2000


      If method createContext() is invoked, the object is no longer serializable.
      Object's field theContext is initialized with non-Serializable class
      instance of java.awt.ColorPaintContext. This is causing the problem.
       
      The test example to reproduce the bug:
      -------------------------------------------------------------
      import java.io.FileOutputStream;
      import java.io.ObjectOutputStream;

      public class test {

        public static void main(String[] args) {
          try {
              java.awt.Color cobj = new java.awt.Color(255,255,255);
              cobj.createContext(
                  new java.awt.image.IndexColorModel(
                      8, 1, new byte[] {0}, new byte[] {0}, new byte[] {0}),
                  new java.awt.Rectangle(1,1,2,3),
                  new java.awt.Rectangle(3,3),
                  new java.awt.geom.AffineTransform(),
                  new java.awt.RenderingHints(null)
              );
              FileOutputStream ostream = new FileOutputStream("gold.tmp");
              ObjectOutputStream objos = new ObjectOutputStream(ostream);
              objos.writeObject(cobj);
              objos.close();
              System.out.println("OKAY");

          } catch (java.io.IOException e) {
              e.printStackTrace();
          }
        }

      }
      -------------------------------------------------------------
      Test output:

      java.io.NotSerializableException: java.awt.ColorPaintContext
              at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)
              at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
              at
      java.io.ObjectOutputStream.outputClassFields(ObjectOutputStream.java:1841)
              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 test.main(test.java:19)
      -------------------------------------------------------------

      ======================================================================

      Attachments

        Activity

          People

            tdv Dmitri Trembovetski (Inactive)
            oovsunw Oov Oov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: