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

use JLabel to show html message get NullPointerException

    Details

      Description

      FULL PRODUCT VERSION :
      1.8.0_20

      ADDITIONAL OS VERSION INFORMATION :
      windows 10

      A DESCRIPTION OF THE PROBLEM :
      when we use JLabel to show html message,if the message is too long , one message will be shown in two lines.
      But if we use the same JLabel to show two html messages, one in two lines and another in one line, there will be a NullPointerException

      REGRESSION. Last worked in version 8u151

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.8.0_20"
      Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
      Java HotSpot(TM) Client VM (build 25.20-b23, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      step 1: use one JLabel to show one html message which is too long that is shown in two lines
      step 2: use the same JLabel to show another html message which is shown in one line
      step 3: repeat step1 and step2 frequently,and after several minutes, the loop stopped and there is a NullPointerException

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      the mesaage was shown properly and there should be no Exception
      ACTUAL -
      the message stopped and the there is a NullPointException

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NullPointerException
      at javax.swing.text.View.setParent(View.java:338)
      at javax.swing.text.CompositeView.setParent(CompositeView.java:136)
      at javax.swing.text.View.setParent(View.java:341)
      at javax.swing.text.CompositeView.setParent(CompositeView.java:136)
      at javax.swing.text.FlowView.setParent(FlowView.java:289)
      at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:75)
      at javax.swing.text.View.setParent(View.java:341)
      at javax.swing.text.CompositeView.setParent(CompositeView.java:136)
      at javax.swing.text.html.BlockView.setParent(BlockView.java:72)
      at javax.swing.text.html.HTMLEditorKit$HTMLFactory$BodyBlockView.setParent(HTMLEditorKit.java:1327)
      at javax.swing.text.View.setParent(View.java:341)
      at javax.swing.text.CompositeView.setParent(CompositeView.java:136)
      at javax.swing.text.html.BlockView.setParent(BlockView.java:72)
      at javax.swing.plaf.basic.BasicHTML.updateRenderer(BasicHTML.java:211)
      at javax.swing.plaf.basic.BasicLabelUI.propertyChange(BasicLabelUI.java:417)
      at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
      at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
      at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
      at java.awt.Component.firePropertyChange(Component.java:8422)
      at javax.swing.JLabel.setText(JLabel.java:330)
      at test.JFrameTest.main(JFrameTest.java:27)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class JFrameTest {

          public static void main(String[] args) {
              JFrame frame = new JFrame("html JLabel test");
              frame.setSize(300, 200);
              JLabel label = new JLabel();
              frame.getContentPane().add(label);
              label.setText("123");
              frame.setLocationRelativeTo(null);
              frame.setVisible(true);
              String str1 = "<html><body>aaaaaaaaabbbbbbbbbbbccccccccdddddddddddddddddddddddddddddddddd中</body></html>";
              String str2 = "<html><body>aaaaa中</body></html>";
              int i = 0;
              while (true) {
                  label.setText(str1);
                  label.setText(str2);
                  try {
                      Thread.sleep(1);
                  } catch (InterruptedException ex) {
                  }
              }
          }
      }
      ---------- END SOURCE ----------

        Attachments

          Activity

            People

            • Assignee:
              psadhukhan Prasanta Sadhukhan
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: