Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6505521

NullPointerException in a HTMLEditorKit after serialize

    XMLWordPrintable

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Linux X 2.6.8-2-386 #1 Tue Aug 16 12:46:35 UTC 2005 i686 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      I'm trying to read a serialized jframe which contains a HTMLEditorKit inside.
      The writing goes just fine, no exceptions (in 1.6; in 1.5 I get a big NotSerializableException because FocusHighlightPainter doesnt implement Serializable).
      Then when I try to read the jframe back, all go fine until I pass the mouse over the jframe (and over the JEditorPane which contains the HTMLEditorKit). At this moment I get a NullPointerException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Compile the test
      2. Execute it. It will create a JFrame, show it, serialize it, dispose the frame, read it back from the file and show it.
      3. Pass the mouse over the JFrame

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      After de-serialize, the jframe must work just like the original

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
              at javax.swing.text.GlyphView$GlyphPainter.getNextVisualPositionFrom(GlyphView.java:1281)
              at javax.swing.text.GlyphView.getNextVisualPositionFrom(GlyphView.java:880)
              at javax.swing.text.Utilities.getNextVisualPositionFrom(Utilities.java:963)
              at javax.swing.text.CompositeView.getNextEastWestVisualPositionFrom(CompositeView.java:732)
              at javax.swing.text.CompositeView.getNextVisualPositionFrom(CompositeView.java:457)
              at javax.swing.text.Utilities.getNextVisualPositionFrom(Utilities.java:963)
              at javax.swing.text.CompositeView.getNextEastWestVisualPositionFrom(CompositeView.java:732)
              at javax.swing.text.CompositeView.getNextVisualPositionFrom(CompositeView.java:457)
              at javax.swing.text.Utilities.getNextVisualPositionFrom(Utilities.java:963)
              at javax.swing.text.CompositeView.getNextEastWestVisualPositionFrom(CompositeView.java:732)
              at javax.swing.text.CompositeView.getNextVisualPositionFrom(CompositeView.java:457)
              at javax.swing.text.Utilities.getNextVisualPositionFrom(Utilities.java:963)
              at javax.swing.text.CompositeView.getNextEastWestVisualPositionFrom(CompositeView.java:732)
              at javax.swing.text.CompositeView.getNextVisualPositionFrom(CompositeView.java:457)
              at javax.swing.text.CompositeView.viewToModel(CompositeView.java:393)
              at javax.swing.text.BoxView.viewToModel(BoxView.java:478)
              at javax.swing.plaf.basic.BasicTextUI$RootView.viewToModel(BasicTextUI.java:1539)
              at javax.swing.plaf.basic.BasicTextUI.viewToModel(BasicTextUI.java:1088)
              at javax.swing.text.html.HTMLEditorKit$LinkController.mouseMoved(HTMLEditorKit.java:655)
              at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:312)
              at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:312)
              at java.awt.Component.processMouseMotionEvent(Component.java:6083)
              at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:3278)
              at java.awt.Component.processEvent(Component.java:5807)
              at java.awt.Container.processEvent(Container.java:2058)
              at java.awt.Component.dispatchEventImpl(Component.java:4410)
              at java.awt.Container.dispatchEventImpl(Container.java:2116)
              at java.awt.Component.dispatchEvent(Component.java:4240)
              at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322)
              at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3999)
              at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916)
              at java.awt.Container.dispatchEventImpl(Container.java:2102)
              at java.awt.Window.dispatchEventImpl(Window.java:2429)
              at java.awt.Component.dispatchEvent(Component.java:4240)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
              at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
              at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      import java.io.*;
      import javax.swing.text.html.*;
      import javax.swing.text.*;

      /*
       * Original:
       * Created on Apr 19, 2005
       * @author Olivier Picard
       *
       * Modified: Eric Ross, 20061217
       */
      public class SerializeEditorPane {

      public static void main(String[] args)
          throws IOException, ClassNotFoundException, BadLocationException
      {
              
              SerializeEditorPane a = new SerializeEditorPane();
              
              JEditorPane pane = new JEditorPane();
      HTMLEditorKit editorKit = new HTMLEditorKit();
              pane.setEditorKit(editorKit);
              
      HTMLDocument document = (HTMLDocument) pane.getDocument();
              String html = "<h1>hello</h1>";
      editorKit.insertHTML(document, document.getLength(), html, 0, 0, null);

              pane.setEditable(false);
              
              // just to make sure the EditorPane was loaded correctly
              JFrame frame = new JFrame("TESTING");
              frame.setSize(500, 500);
              frame.getContentPane().add(pane);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
              
      File file = File.createTempFile("test","tmp");
              OutputStream outStream = new FileOutputStream(file);
              ObjectOutputStream out = new ObjectOutputStream(outStream);
              out.writeObject(frame);
              out.flush();
              out.close();

      frame.setVisible(false);
      frame.dispose();


      FileInputStream fis = new FileInputStream(file);
      ObjectInputStream in = new ObjectInputStream(fis);
      JFrame f = (JFrame) in.readObject();
      in.close();
      fis.close();

      f.setVisible(true);

          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            Assignee:
            peterz Peter Zhelezniakov
            Reporter:
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Imported:
              Indexed: