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

JEditorPane.setEditable(false) produces NullPointerException from StyleSheet.getRule()

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Cannot Reproduce
    • Affects Version/s: 6u24
    • Fix Version/s: 6
    • Component/s: client-libs
    • Labels:
      None

      Description

      The following snippet of code in NetBeans sometimes produces NullPointerException. I am including the code snippet, the html file which is passed to the JEditorPane instance, and the stacktrace of the exception.

      The code snippet (the exception is raised on the line where setEditable() is called):

      browser = new JEditorPane();
      try {
        URL resource = new URL("nbresloc:/org/netbeans/modules/uihandler/Connecting.html");
        browser.setPage(resource);
      } catch (IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
      }
      browser.setBorder(javax.swing.BorderFactory.createEmptyBorder(8, 8, 0, 8));
      browser.setPreferredSize(dim);
      browser.setEditable(false);
      browser.setEditorKit(new HTMLEditorKit());
      browser.setBackground(new JLabel().getBackground());
      browser.addHyperlinkListener(SubmitInteractive.this);
      JScrollPane p = new JScrollPane();
      p.setViewportView(browser);
      p.setBorder(BorderFactory.createEmptyBorder());
      p.setPreferredSize(dim);
      DialogDescriptor descr = findDD();
      descr.setMessage(p);
      ...

      The html file (Connecting.html):

      <!DOCTYPE html
      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
              <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
              <title>Connecting to UI Gestures Collector</title>
          </head>
      <body>
      <h1>Connecting to UI Gestures Collector</h1>
      <center>
      <p>
          Loading initial welcome page. Please wait...
      </p>
      </center>
      </body>
      </html>

      The exception raised from the code:

      java.lang.NullPointerException
      at javax.swing.text.html.StyleSheet.getRule(StyleSheet.java:194)
      at javax.swing.text.html.StyleSheet$ViewAttributeSet.<init>(StyleSheet.java:2676)
      at javax.swing.text.html.StyleSheet.getViewAttributes(StyleSheet.java:330)
      at javax.swing.text.html.BlockView.setPropertiesFromAttributes(BlockView.java:387)
      at javax.swing.text.html.BlockView.setParent(BlockView.java:57)
      at javax.swing.text.html.HTMLEditorKit$HTMLFactory$BodyBlockView.setParent(HTMLEditorKit.java:1287)
      at javax.swing.text.CompositeView.replace(CompositeView.java:200)
      at javax.swing.text.BoxView.replace(BoxView.java:164)
      at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
      at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
      at javax.swing.text.html.BlockView.setParent(BlockView.java:55)
      at javax.swing.plaf.basic.BasicTextUI$RootView.setView(BasicTextUI.java:1316)
      at javax.swing.plaf.basic.BasicTextUI.setView(BasicTextUI.java:678)
      at javax.swing.plaf.basic.BasicTextUI.modelChanged(BasicTextUI.java:667)
      at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.propertyChange(BasicTextUI.java:1792)
      at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:339)
      at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:276)
      at java.awt.Component.firePropertyChange(Component.java:8154)
      at javax.swing.text.JTextComponent.setEditable(JTextComponent.java:1781)
      ...

      You can see the original NetBeans bug report at
      https://netbeans.org/bugzilla/show_bug.cgi?id=188677#c11

      I saw the exception being reported with various versions of JDK 6 updates. The stacktrace above is taken from the report with user running on top of JDK 6u24.

      Is this a bug in JDK classes, or is there anything we should do better in our code?

      Thanks for your evalution!

        Attachments

          Activity

            People

            • Assignee:
              rupashka Pavel Porvatov (Inactive)
              Reporter:
              anebuzel Antonín Nebuželský
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: