Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4085359
Votes 0
Synopsis ScrollPane is not serializable ScrollPane is not serializable
Category java:classes_awt
Reported Against 1.1
Release Fixed
State 11-Closed, duplicate of 4085659, bug
Priority: 4-Low
Related Bugs 4085659
Submit Date 10-OCT-1997
Description
Detailed Description:
  Try this.
---------
import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class test {
  public static void main(String args[]) throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(
      new ByteArrayOutputStream());
    ScrollPane sp = new ScrollPane();
    sp.getHAdjustable().addAdjustmentListener(new AdjustmentListener() {
      public void adjustmentValueChanged(AdjustmentEvent ev) {}
    });	// this is key
    oos.writeObject(sp);
  }
}
Work Around
12/7/99   xxxxx@xxxxx   -- explicitly remove the AdjustmentListener before
attempting to serialize the ScrollPane.


import java.awt.*;
import java.awt.event.*;
import java.io.*;

public class Test4085359
        implements AdjustmentListener, Serializable {

  public Test4085359() throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(
      new ByteArrayOutputStream());
    
        ScrollPane sp = new ScrollPane();

        sp.getHAdjustable().addAdjustmentListener(this);
	// adjustment listener kept as static variable by component/container,
	//	so no way to make it transient -- thus, remove explicitly
	//	before trying to serialize
        sp.getHAdjustable().removeAdjustmentListener(this);

    	oos.writeObject(sp);
  }
  
  public void adjustmentValueChanged(AdjustmentEvent ev) {
  }

  public static void main(String args[]) throws IOException {
        Test4085359 test = new Test4085359();
  }

}

Evaluation
In JDK 1.1.4, the result is 
java.io.NotSerializableException: java.awt.AWTEventMulticaster
        at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java)
        atjava.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java)
        at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java)
        atjava.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java)
        at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java)
        at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java)
        at test.main(test.java:13)

--------------------

12/7/99   xxxxx@xxxxx   -- A component's AdjustmentListener is kept as a static variable , so there's no way to make it transient (to allow comp to be serialized).
Not clear whether this is a bug, or a design decision made as part of the
fixes for 4027305.  The components that HAVE been made serializable are being documented as part of bug # 4085659.  I'm marking this as a dupe of 4085659. 
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang