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

NPE in HTMLEditorKit

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • client-libs



      Name: jk109818 Date: 10/08/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"

      FULL OPERATING SYSTEM VERSION :

      Any OS

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Any OS

      A DESCRIPTION OF THE PROBLEM :
      When navigating using an HTML Editor Pane, sometimes an NPE
      is thrown on some web pages. The stack trace shows that
      sometimes the Shape object returned is null.

      Pseudo-source:

      /**
       * Embed this in a swing app
       */
      public class HelpView extends JOptionPane {
          
          private String title;
          private JEditorPane editorPane;
          
          /** Creates a new instance of HelpView */
          public HelpView() {
              editorPane = factory.createEditorPane();
              editorPane.setEditable(false);
              editorPane.setPreferredSize(new Dimension(352, 264));
              editorPane.addHyperlinkListener(new
      HyperlinkListener() {
                  public void hyperlinkUpdate(HyperlinkEvent e) {
                      if (e.getEventType() ==
      HyperlinkEvent.EventType.ACTIVATED) {
                          setURL(e.getURL());
                      }
                  }
              });
              JButton closeButton = new JButton("Close");
              // ...code to connect the button to disposal here...
              setOptions(new Object[] { closeButton });
              setInitialValue(closeButton);
              
              JScrollPane scrollPane =
      factory.createScrollPane(editorPane);
              setMessage(new Object[] { scrollPane });
          }
          
          /**
           * Sets the page for this view
           */
          public void setURL(URL url) {
              try {
                  // We have to parse the document to find the title
                  InputStream iStream = url.openStream();
                  InputStreamReader reader = new
      InputStreamReader(iStream);
                  HTMLCallback callback = new HTMLCallback();
                  new ParserDelegator().parse(reader, callback, true);
                  editorPane.setPage(url);
              } catch (IOException e) {
                  e.printStackTrace(); // Remind : Handle 404
              }
          }

          /**
           * Parser callback used to retrieve any information from
      the HTML document
           * that we may want to use to update other controls
      (such as setting the
           * title of the owning frame).
           */
          private class HTMLCallback extends
      HTMLEditorKit.ParserCallback {
              
              boolean isTitle = false;
              
              public void handleStartTag(HTML.Tag t,
      MutableAttributeSet a, int pos) {
                  if (t == HTML.Tag.TITLE) {
                      isTitle = true;
                  }
              }
              
              public void handleEndTag(HTML.Tag t, int pos) {
                  if (t == HTML.Tag.TITLE) {
                      isTitle = false;
                  }
              }
              
              public void handleText(char[] data, int pos) {
                  if (isTitle) {
                      title = new String(data);
                  }
              }
          }
       
      }


      java.lang.NullPointerException

      at
      javax.swing.text.html.HTMLEditorKit$LinkController.doesElementContainLocation(HTMLEditorKit.java:733)

      at
      javax.swing.text.html.HTMLEditorKit$LinkController.mouseMoved(HTMLEditorKit.java:631)

      at
      java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:268)

      at
      java.awt.Component.processMouseMotionEvent(Component.java:5066)

      at
      javax.swing.JComponent.processMouseMotionEvent(JComponent.java:2763)

      at java.awt.Component.processEvent(Component.java:4822)

      at java.awt.Container.processEvent(Container.java:1380)

      at java.awt.Component.dispatchEventImpl(Component.java:3526)

      at java.awt.Container.dispatchEventImpl(Container.java:1437)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at
      java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)

      at
      java.awt.LightweightDispatcher.processMouseEvent(Container.java:2942)

      at
      java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)

      at java.awt.Container.dispatchEventImpl(Container.java:1423)

      at java.awt.Window.dispatchEventImpl(Window.java:1566)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)

      at
      java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)

      at
      java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)

      at
      java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:134)

      at java.awt.Dialog.show(Dialog.java:524)

      at java.awt.Component.show(Component.java:1128)

      at java.awt.Component.setVisible(Component.java:1083)

      at
      com.teleias.gui.action.ShowWindowAction.showWindow(ShowWindowAction.java:190)

      at
      com.teleias.gui.action.ShowWindowAction.actionPerformed(ShowWindowAction.java:147)

      at
      javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1767)

      at
      javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1820)

      at
      javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

      at
      javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)

      at javax.swing.AbstractButton.doClick(AbstractButton.java:289)

      at
      javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1092)

      at
      javax.swing.plaf.basic.BasicMenuItemUI$MenuDragMouseHandler.menuDragMouseReleased(BasicMenuItemUI.java:991)

      at
      javax.swing.JMenuItem.fireMenuDragMouseReleased(JMenuItem.java:582)

      at
      javax.swing.JMenuItem.processMenuDragMouseEvent(JMenuItem.java:479)

      at javax.swing.JMenuItem.processMouseEvent(JMenuItem.java:426)

      at
      javax.swing.MenuSelectionManager.processMouseEvent(MenuSelectionManager.java:274)

      at
      javax.swing.plaf.basic.BasicMenuUI$MouseInputHandler.mouseReleased(BasicMenuUI.java:334)

      at
      java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:227)

      at java.awt.Component.processMouseEvent(Component.java:5021)

      at java.awt.Component.processEvent(Component.java:4818)

      at java.awt.Container.processEvent(Container.java:1380)

      at java.awt.Component.dispatchEventImpl(Component.java:3526)

      at java.awt.Container.dispatchEventImpl(Container.java:1437)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at
      java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)

      at
      java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)

      at
      java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)

      at java.awt.Container.dispatchEventImpl(Container.java:1423)

      at java.awt.Window.dispatchEventImpl(Window.java:1566)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)

      at
      java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)

      at
      java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)

      at
      java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

      at
      java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      See description.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.NullPointerException

      at
      javax.swing.text.html.HTMLEditorKit$LinkController.doesElementContainLocation(HTMLEditorKit.java:733)

      at
      javax.swing.text.html.HTMLEditorKit$LinkController.mouseMoved(HTMLEditorKit.java:631)

      at java.awt.AWTEventMulticaster.mouseMoved(AWTEventMulticaster.java:268)

      at java.awt.Component.processMouseMotionEvent(Component.java:5066)

      at javax.swing.JComponent.processMouseMotionEvent(JComponent.java:2763)

      at java.awt.Component.processEvent(Component.java:4822)

      at java.awt.Container.processEvent(Container.java:1380)

      at java.awt.Component.dispatchEventImpl(Component.java:3526)

      at java.awt.Container.dispatchEventImpl(Container.java:1437)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)

      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2942)

      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)

      at java.awt.Container.dispatchEventImpl(Container.java:1423)

      at java.awt.Window.dispatchEventImpl(Window.java:1566)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)

      at
      java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:134)

      at java.awt.Dialog.show(Dialog.java:524)

      at java.awt.Component.show(Component.java:1128)

      at java.awt.Component.setVisible(Component.java:1083)

      at com.teleias.gui.action.ShowWindowAction.showWindow(ShowWindowAction.java:190)

      at com.teleias.gui.action.ShowWindowAction.actionPerformed(ShowWindowAction.java:147)

      at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1767)

      at
      javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1820)

      at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)

      at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)

      at javax.swing.AbstractButton.doClick(AbstractButton.java:289)

      at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1092)

      at
      javax.swing.plaf.basic.BasicMenuItemUI$MenuDragMouseHandler.menuDragMouseReleased(BasicMenuItemUI.java:991)

      at javax.swing.JMenuItem.fireMenuDragMouseReleased(JMenuItem.java:582)

      at javax.swing.JMenuItem.processMenuDragMouseEvent(JMenuItem.java:479)

      at javax.swing.JMenuItem.processMouseEvent(JMenuItem.java:426)

      at javax.swing.MenuSelectionManager.processMouseEvent(MenuSelectionManager.java:274)

      at
      javax.swing.plaf.basic.BasicMenuUI$MouseInputHandler.mouseReleased(BasicMenuUI.java:334)

      at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:227)

      at java.awt.Component.processMouseEvent(Component.java:5021)

      at java.awt.Component.processEvent(Component.java:4818)

      at java.awt.Container.processEvent(Container.java:1380)

      at java.awt.Component.dispatchEventImpl(Component.java:3526)

      at java.awt.Container.dispatchEventImpl(Container.java:1437)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3214)

      at java.awt.LightweightDispatcher.processMouseEvent(Container.java:2929)

      at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2859)

      at java.awt.Container.dispatchEventImpl(Container.java:1423)

      at java.awt.Window.dispatchEventImpl(Window.java:1566)

      at java.awt.Component.dispatchEvent(Component.java:3367)

      at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)

      at
      java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:190)

      at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:144)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)

      at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)

      at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)



      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

      ---------- BEGIN SOURCE ----------
      /**
       * Embed this in a swing app
       * Note that this is only pseudo-source and may not compile outside of the
       * context in which it was used.
       */
      public class HelpView extends JOptionPane {
          
          private String title;
          private JEditorPane editorPane;
          
          /** Creates a new instance of HelpView */
          public HelpView() {
              editorPane = factory.createEditorPane();
              editorPane.setEditable(false);
              editorPane.setPreferredSize(new Dimension(352, 264));
              editorPane.addHyperlinkListener(new HyperlinkListener() {
                  public void hyperlinkUpdate(HyperlinkEvent e) {
                      if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                          setURL(e.getURL());
                      }
                  }
              });
              JButton closeButton = new JButton("Close");
              // ...code to connect the button to disposal here...
              setOptions(new Object[] { closeButton });
              setInitialValue(closeButton);
              
              JScrollPane scrollPane = factory.createScrollPane(editorPane);
              setMessage(new Object[] { scrollPane });
          }
          
          /**
           * Sets the page for this view
           */
          public void setURL(URL url) {
              try {
                  // We have to parse the document to find the title
                  InputStream iStream = url.openStream();
                  InputStreamReader reader = new InputStreamReader(iStream);
                  HTMLCallback callback = new HTMLCallback();
                  new ParserDelegator().parse(reader, callback, true);
                  editorPane.setPage(url);
              } catch (IOException e) {
                  e.printStackTrace(); // Remind : Handle 404
              }
          }

          /**
           * Parser callback used to retrieve any information from the HTML document
           * that we may want to use to update other controls (such as setting the
           * title of the owning frame).
           */
          private class HTMLCallback extends HTMLEditorKit.ParserCallback {
              
              boolean isTitle = false;
              
              public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) {
                  if (t == HTML.Tag.TITLE) {
                      isTitle = true;
                  }
              }
              
              public void handleEndTag(HTML.Tag t, int pos) {
                  if (t == HTML.Tag.TITLE) {
                      isTitle = false;
                  }
              }
              
              public void handleText(char[] data, int pos) {
                  if (isTitle) {
                      title = new String(data);
                  }
              }
          }
       
      }


      ---------- END SOURCE ----------
      (Review ID: 164564)
      ======================================================================

            idk Igor Kushnirskiy (Inactive)
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: