JDK-6189117 : REGRESSION: JScrollBar does NOT serialize if overridden in JDK 5.0
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-11-01
  • Updated: 2010-04-02
  • Resolved: 2004-11-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
5.0Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]


A DESCRIPTION OF THE PROBLEM :
It appears that if you override a JScrollBar in 1.5 it throws an exception when trying to serialize.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the following code under 1.5
public class TestSerialization {

    public static void main(String[] args) {
        try {
            (new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream())).writeObject(new Scrollbar());
            System.exit(0);
        }
        catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }

    private static class Scrollbar extends javax.swing.JScrollBar {
        public Scrollbar() {
        }
    }
}


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Process finished with exit code 0
ACTUAL -
ava.io.NotSerializableException: javax.swing.plaf.metal.MetalScrollBarUI
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
	at java.io.ObjectOutputStream.access$100(ObjectOutputStream.java:135)
	at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1512)
	at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:418)
	at java.awt.Container.writeObject(Container.java:3461)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
	at TestSerialization.main(TestSerialization.java:6)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)

ERROR MESSAGES/STACK TRACES THAT OCCUR :
ava.io.NotSerializableException: javax.swing.plaf.metal.MetalScrollBarUI
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
	at java.io.ObjectOutputStream.access$100(ObjectOutputStream.java:135)
	at java.io.ObjectOutputStream$PutFieldImpl.writeFields(ObjectOutputStream.java:1512)
	at java.io.ObjectOutputStream.writeFields(ObjectOutputStream.java:418)
	at java.awt.Container.writeObject(Container.java:3461)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:890)
	at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1333)
	at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284)
	at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1073)
	at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
	at TestSerialization.main(TestSerialization.java:6)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:585)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
public class TestSerialization {

    public static void main(String[] args) {
        try {
            (new java.io.ObjectOutputStream(new java.io.ByteArrayOutputStream())).writeObject(new Scrollbar());
            System.exit(0);
        }
        catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }

    private static class Scrollbar extends javax.swing.JScrollBar {
        public Scrollbar() {
        }
    }
}

---------- END SOURCE ----------

Release Regression From : 1.4.2
The above release value was the last known release where this 
bug was known to work. Since then there has been a regression.
###@###.### 11/1/04 23:41 GMT

Comments
EVALUATION The class "javax.swing.plaf.metal.MetalScrollBarUI" is indeed not serializable; it does not implement the java.io.Serializable interface. It was not serializable in 1.4.2 either. The difference here would appear to be whether or not a MetalScrollBarUI object is attempted to be serialized as part of serializing a javax.swing.JScrollBar instance; in 1.4.2, apparently, that was not the case. The submitted test case makes a point of subclassing JScrollBar, and that appears important; the test passes for me if I change it to serialize "new javax.swing.JScrollBar()" instead. This aspect seems at least superficially related to 6190713. The NotSerializableException stack trace shows that the problematic MetalScrollBarUI object is directly one of the fields written by java.awt.Container.writeObject using the ObjectOutputStream.PutField API. Of the non-primitive fields declared in Container's serialPersistentFields, the field "layoutMgr" would seem to be the culprit-- it's the only with with a type (LayoutManager) that is assignable from MetalScrollBarUI. Instrumenting the test to invoke getLayout on the Scrollbar confirms that it is indeed a MetalScrollBarUI. I am recategorizing this CR to java/classes_swing for further analysis by people with expertise in this Swing/AWT code and what might have changed here for 5.0. Also, see Comments for some further information. ###@###.### 2004-11-16 23:04:38 GMT This is a dupliate of 6190713, refer to it for more information. ###@###.### 2004-11-16 23:44:31 GMT
16-11-2004