XStream
  1. XStream
  2. XSTR-130

NPE when deserializing DefaultListModel

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.2
    • Component/s: None
    • Labels:
      None

      Description

      Serializing and deserializing a DefaultListModel does lead to a NPE when a JList gets the deserialized version. The following code does demonstrate that:

      ---------------------------- Code ---------------

      import javax.swing.*;
      import com.thoughtworks.xstream.XStream;
      import com.thoughtworks.xstream.io.xml.DomDriver;
      import java.io.*;

      public class Test extends JFrame {

      public static void main(String[] args) throws IOException

      { final DefaultListModel m1 = new DefaultListModel(); final JList list = new JList(); list.setModel(m1); final XStream x = new XStream(new DomDriver()); x.toXML(m1, new FileWriter("C:/test.xml")); final DefaultListModel m2 = (DefaultListModel) x.fromXML(new FileReader("C:/test.xml")); list.setModel(m2); }

      }

      ----------------------- Output -------------------

      java.lang.NullPointerException
      at javax.swing.event.EventListenerList.add(EventListenerList.java:177)
      at javax.swing.AbstractListModel.addListDataListener(AbstractListModel.java:42)
      at javax.swing.plaf.basic.BasicListUI$PropertyChangeHandler.propertyChange(BasicListUI.java:1643)
      at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
      at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
      at javax.swing.JComponent.firePropertyChange(JComponent.java:3819)
      at javax.swing.JList.setModel(JList.java:1219)
      at Test.main(Test.java:43)
      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:324)
      at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
      Exception in thread "main"

      I would appreciate to hear what I can do to get around it.

      Thanks
      Daniel Frey

        People

        • Assignee:
          Unassigned
          Reporter:
          Daniel Frey
        • Votes:
          0 Vote for this issue
          Watchers:
          1 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: