-
Enhancement
-
Resolution: Unresolved
-
P4
-
None
-
6
-
Cause Known
-
x86
-
solaris_10
FULL PRODUCT VERSION :
java version "1.6.0-rc"
A DESCRIPTION OF THE PROBLEM :
AlphaComposite is not Serializable. It should be made Serializable and a good strategy for doing so would be:
1. Implement the writeReplace method. Return an Object that stores the rule and alpha rule.
2. Upon reading, use the readResolve method of the custom object to return an AlphaComposite derived from the static factory method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this test, watch it crash:
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
AlphaComposite Serialized and then unserialized ok.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.NotSerializableException: java.awt.AlphaComposite
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at SerializeAlphaComposite.main(SerializeAlphaComposite.java:11)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.io.*;
public class SerializeAlphaComposite implements Serializable{
public static void main(String ... args){
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_OVER, 1.0f);
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ac);
byte[] data = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bais);
AlphaComposite ac2 = (AlphaComposite)ois.readObject();
}catch(Exception x){ x.printStackTrace(); }
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
subclass AlphaComposite and make it Serializable
java version "1.6.0-rc"
A DESCRIPTION OF THE PROBLEM :
AlphaComposite is not Serializable. It should be made Serializable and a good strategy for doing so would be:
1. Implement the writeReplace method. Return an Object that stores the rule and alpha rule.
2. Upon reading, use the readResolve method of the custom object to return an AlphaComposite derived from the static factory method.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run this test, watch it crash:
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
AlphaComposite Serialized and then unserialized ok.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
java.io.NotSerializableException: java.awt.AlphaComposite
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
at SerializeAlphaComposite.main(SerializeAlphaComposite.java:11)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.io.*;
public class SerializeAlphaComposite implements Serializable{
public static void main(String ... args){
AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.DST_OVER, 1.0f);
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(ac);
byte[] data = baos.toByteArray();
ByteArrayInputStream bais = new ByteArrayInputStream(data);
ObjectInputStream ois = new ObjectInputStream(bais);
AlphaComposite ac2 = (AlphaComposite)ois.readObject();
}catch(Exception x){ x.printStackTrace(); }
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
subclass AlphaComposite and make it Serializable