-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
None
-
beta
-
sparc
-
solaris_2.6
Name: ksR10052 Date: 09/29/2000
Headless support was introduced in merlin (CCC request 4281163 ).
However, 4281163 does not fully consider serialization as a back door to
creation of "objects that inherit from a heavyweight component". It is
possible to create such objects through serialization (see example below).
This is not good.
The readObject() method should be added/modified to throw HeadlessException for
all the heavyweight components (mentioned in CCC request 4281163). The CCC request
should be also updated to reflect this behavior.
Here are the examples demonstrating the bug:
------- test44.java ------------------------------
import java.awt.*;
import java.io.*;
public class test44 {
public static void main (String argv[]) {
try {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("component.serial"));
oos.writeObject(new Button());
} catch (IOException e) {
}
}
}
-------------------------------------------------
------- test45.java ------------------------------
import java.awt.*;
import java.io.*;
public class test45 {
public static void main (String argv[]) {
try {
ObjectInputStream oos = new ObjectInputStream(new FileInputStream("component.serial"));
try {
System.out.println(oos.readObject());
} catch (ClassNotFoundException cnfe) {}
} catch (IOException e) {
}
}
}
-------------------------------------------------
test run:
1) verify that HeadlessException is thrown upon Button construction:
#>/set/java/jdk1.4/solaris/bin/java -Djava.awt.headless=true test44
Exception in thread "main" java.awt.HeadlessException
at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:112)
at java.awt.Button.<init>(Button.java:134)
at java.awt.Button.<init>(Button.java:123)
at test44.main(test44.java:9)
2) write serialized Button to a file:
#>/set/java/jdk1.4/solaris/bin/java test44
[sko@knight:443] -- << ~/mytests >>
3) successfully construct Button object in headless environment through serialization:
#>/set/java/jdk1.4/solaris/bin/java -Djava.awt.headless=true test45
java.awt.Button[button0,0,0,0x0,invalid,label=]
======================================================================