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

text package in swing generates NullPointerException in 1.3.0

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      beta2
    • CPU:
      sparc
    • OS:
      solaris_8

      Description

        I have a piece of code that works under JDK 1.8_09a and 1.2.2_05a but
      generates NullPointerException under 1.3. The code and stack trace is enclosed
      for your reference.

      The code basically allow users to click url links inside a displayed
      html document (in a JEditorPane) and then display the linked document. The
      document is always properly displayed and the NPE only happens sporadically.

      I spent a lot of time searching the bug database, but can not find
      something similar. I suspected that this may be caused by the non-thread-safe
      aspect of swing and I inserted SwingUtilities.isEventDispatchThread() inquiries
      before text.setPage(), text.setCursor(), and repaint() just to make sure they
      are all running in the event dispatching thread, and they are.

      HTML files are included as bug report Attachments. Thanks.

      < stack trace>


      Exception occurred during event dispatching:
      java.lang.NullPointerException
              at
      javax.swing.text.ParagraphView$Row.modelToView(ParagraphView.java:688)
              at javax.swing.text.CompositeView.modelToView(CompositeView.java:238)
              at javax.swing.text.BoxView.modelToView(BoxView.java:344)
              at javax.swing.text.CompositeView.modelToView(CompositeView.java:238)
              at javax.swing.text.BoxView.modelToView(BoxView.java:344)
              at
      javax.swing.plaf.basic.BasicTextUI$RootView.modelToView(BasicTextUI.java:1245)
              at javax.swing.plaf.basic.BasicTextUI.modelToView(BasicTextUI.java:818)
              at javax.swing.text.DefaultCaret.repaintNewCaret(DefaultCaret.java:872)
              at javax.swing.text.DefaultCaret$1.run(DefaultCaret.java:851)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:331)
              at
      java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)

      < code snippets >

        public class FileViewer extends JDialog implements HyperlinkListener
          
          // in the constructor:
          text = new JEditorPane();
          text.setEditable(false);
          text.addHyperlinkListener(this);
          
        public void hyperlinkUpdate(HyperlinkEvent e) {
          if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            URL link = e.getURL();
            if (link == null) {
              return;
            }
            linkActivated(link);
          }
        }
        protected synchronized void linkActivated(URL u) {
          Cursor c = text.getCursor();
          Cursor waitCursor = Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);
          text.setCursor(waitCursor);
          Document doc = text.getDocument();
          try {
            text.setPage(u);
          } catch (MalformedURLException e) {
            System.out.println("FileViewer.linkActivated: Malformed URL");
            text.setDocument(doc);
            Configurator.showStatus("Malformed help URL",ProgressMonitor.ERROR);
          } catch (IOException e) {
            System.out.println("FileViewer.linkActivated: IO Exception");
            text.setDocument(doc);
            Configurator.showStatus("IO Error",ProgressMonitor.ERROR);
          } finally {
            text.setCursor(c);
            repaint();
          }
        }


      elaine.hsu@East 2000-12-14

        Attachments

          Activity

            People

            Assignee:
            svioletsunw Scott Violet (Inactive)
            Reporter:
            chuhsu Elaine Hsu
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: