-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
x86
-
windows_nt
Name: skT45625 Date: 06/30/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
The serialization part is successful without any problems, but deserialization
fails with NullPointerException. The problem occurs only when using JList,
JScrollPane and JSplitPane together. If even one is missing, the problem does
not show up!
The following code shows how to reproduce the bug. Just change the testCase
number to CASE_4, recompile and run to see the failure. All other cases run
successfully.
import javax.swing.*;
import java.io.*;
public class Main
{
public static final int CASE_1 = 1;
public static final int CASE_2 = 2;
public static final int CASE_3 = 3;
public static final int CASE_4 = 4;
public static final void main(String[] args)
{
JFrame frame = new JFrame();
frame.setBounds(new java.awt.Rectangle(50, 50, 200, 110));
JSplitPane splitPane;
JScrollPane scrollPane;
JList list = new JList();
java.util.Vector listData = new java.util.Vector();
listData.add("One");
listData.add("Two");
listData.add("Three");
listData.add("Four");
listData.add("Five");
listData.add("Six");
listData.add("Seven");
list.setListData(listData);
int testCase = CASE_4; // Change this to one of the four constants
// defined above to observe the different cases.
switch(testCase)
{
case CASE_1: // SUCCESS
scrollPane = new JScrollPane(list); // with a view
frame.getContentPane().add(scrollPane); // add scrollPane
break;
case CASE_2: // SUCCESS
splitPane = new JSplitPane();
splitPane.setLeftComponent(list); // no scrollPane
frame.getContentPane().add(splitPane); // add splitPane
break;
case CASE_3: // SUCCESS
scrollPane = new JScrollPane(); // without a view
splitPane = new JSplitPane();
splitPane.setLeftComponent(scrollPane);
frame.getContentPane().add(splitPane); // add splitPane
break;
case CASE_4: // FAILURE
scrollPane = new JScrollPane(list); // with a view
splitPane = new JSplitPane();
splitPane.setLeftComponent(scrollPane);
frame.getContentPane().add(splitPane); // add splitPane
break;
default: // This succeeds. The only difference is JLabel instead of JList
scrollPane = new JScrollPane(new JLabel("Test"));
splitPane = new JSplitPane();
splitPane.setLeftComponent(scrollPane);
frame.getContentPane().add(splitPane); // add splitPane
break;
}
Object deserializedCopy = null;
try
{
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new
ObjectOutputStream(byteArrayOutputStream);
objectOutputStream.writeObject(frame);
objectOutputStream.flush();
objectOutputStream.close();
byte[] byteArray = byteArrayOutputStream.toByteArray();
ByteArrayInputStream byteArrayInputStream = new
ByteArrayInputStream(byteArray);
ObjectInputStream objectInputStream = new
ObjectInputStream(byteArrayInputStream);
deserializedCopy = objectInputStream.readObject();
objectInputStream.close();
}
catch(Exception ex)
{
javax.swing.JOptionPane.showMessageDialog(null, ex.toString());
ex.printStackTrace();
}
((JFrame)deserializedCopy).setVisible(tru
(Review ID: 106740)
======================================================================