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

HTMLDocument.wait() thread lock after calling JPanel.pack() at startup

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      This is a very intermittent problem but could be successfully reproduced on Windows 10 using latest available versions of Java 10 and Java 11 with multiple tries and the right conditions (may help to have high background CPU load).


      A DESCRIPTION OF THE PROBLEM :
      Call to JPanel.pack() from thread main gets stuck waiting on HTMLDocument while AWT-EventQueue-0] is stuck waiting for: Component$AWTTreeLock , which is owned by thread main.

      com.test.Main at localhost:50095 (Suspended)
      Thread [main] (Suspended)
      owns: BoxLayout (id=24)
      owns: Component$AWTTreeLock (id=25)
      waited by: Thread [AWT-EventQueue-0] (Suspended)
      waiting for: HTMLDocument (id=23)
      Object.wait(long) line: not available [native method]
      HTMLDocument(Object).wait() line: 328
      HTMLDocument(AbstractDocument).readLock() line: 1398
      BasicEditorPaneUI(BasicTextUI).getMinimumSize(JComponent) line: 980
      JEditorPane(JComponent).getMinimumSize() line: 1760
      BoxLayout.checkRequests() line: 479
      BoxLayout.layoutContainer(Container) line: 421
      JPanel(Container).layout() line: 1537
      JPanel(Container).doLayout() line: 1526
      JPanel(Container).validateTree() line: 1722
      JPanel(Container).validateTree() line: 1731
      JPanel(Container).validateTree() line: 1731
      JLayeredPane(Container).validateTree() line: 1731
      JRootPane(Container).validateTree() line: 1731
      Main$testThreadLockPanel(Container).validateTree() line: 1731
      Main$testThreadLockPanel(Container).validate() line: 1657
      Main$testThreadLockPanel(Container).validateUnconditionally() line: 1694
      Main$testThreadLockPanel(Window).pack() line: 835
      Main$testThreadLockPanel.<init>(Main) line: 123
      Main.<init>() line: 48
      Main.main(String[]) line: 37
      Daemon System Thread [Reference Handler] (Suspended)
      Reference<T>.waitForReferencePendingList() line: not available [native method]
      Reference<T>.processPendingReferences() line: 241
      Reference$ReferenceHandler.run() line: 213
      Daemon System Thread [Finalizer] (Suspended)
      waiting for: ReferenceQueue$Lock (id=26)
      Object.wait(long) line: not available [native method]
      ReferenceQueue<T>.remove(long) line: 155
      ReferenceQueue<T>.remove() line: 176
      Finalizer$FinalizerThread.run() line: 170
      Daemon System Thread [Signal Dispatcher] (Suspended)
      Daemon System Thread [Attach Listener] (Suspended)
      Daemon System Thread [Common-Cleaner] (Suspended)
      waiting for: ReferenceQueue$Lock (id=51)
      Object.wait(long) line: not available [native method]
      ReferenceQueue<T>.remove(long) line: 155
      CleanerImpl.run() line: 148
      InnocuousThread(Thread).run() line: 834
      InnocuousThread.run() line: 134
      Daemon System Thread [Java2D Disposer] (Suspended)
      waiting for: ReferenceQueue$Lock (id=52)
      Object.wait(long) line: not available [native method]
      ReferenceQueue<T>.remove(long) line: 155
      ReferenceQueue<T>.remove() line: 176
      Disposer.run() line: 144
      Thread.run() line: 834
      System Thread [AWT-Shutdown] (Suspended)
      waiting for: Object (id=53)
      Object.wait(long) line: not available [native method]
      Object.wait() line: 328
      AWTAutoShutdown.run() line: 291
      Thread.run() line: 834
      Daemon System Thread [AWT-Windows] (Suspended)
      WToolkit.eventLoop() line: not available [native method]
      WToolkit.run() line: 303
      Thread.run() line: 834
      Thread [AWT-EventQueue-0] (Suspended)
      waiting for: Component$AWTTreeLock (id=25)
      JEditorPane(Component).invalidate() line: 3016
      JEditorPane(Container).invalidate() line: 1614
      JEditorPane(JComponent).revalidate() line: 4891
      BasicTextUI$RootView.preferenceChanged(View, boolean, boolean) line: 1505
      BlockView(View).preferenceChanged(View, boolean, boolean) line: 287
      BlockView(BoxView).preferenceChanged(View, boolean, boolean) line: 287
      HTMLEditorKit$HTMLFactory$BodyBlockView(View).preferenceChanged(View, boolean, boolean) line: 287
      HTMLEditorKit$HTMLFactory$BodyBlockView(BoxView).preferenceChanged(View, boolean, boolean) line: 287
      ParagraphView(View).preferenceChanged(View, boolean, boolean) line: 287
      ParagraphView(BoxView).preferenceChanged(View, boolean, boolean) line: 287
      FlowView$LogicalView(View).preferenceChanged(View, boolean, boolean) line: 287
      BRView(View).preferenceChanged(View, boolean, boolean) line: 287
      BRView(GlyphView).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 955
      BRView(LabelView).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 304
      BRView(InlineView).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 93
      FlowView$LogicalView(View).forwardUpdateToView(View, DocumentEvent, Shape, ViewFactory) line: 1241
      FlowView$LogicalView.forwardUpdateToView(View, DocumentEvent, Shape, ViewFactory) line: 811
      FlowView$LogicalView(View).forwardUpdate(DocumentEvent$ElementChange, DocumentEvent, Shape, ViewFactory) line: 1172
      FlowView$LogicalView.forwardUpdate(DocumentEvent$ElementChange, DocumentEvent, Shape, ViewFactory) line: 821
      FlowView$LogicalView(View).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 797
      ParagraphView(FlowView).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 291
      ParagraphView(ParagraphView).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 781
      HTMLEditorKit$HTMLFactory$BodyBlockView(View).forwardUpdateToView(View, DocumentEvent, Shape, ViewFactory) line: 1241
      HTMLEditorKit$HTMLFactory$BodyBlockView(View).forwardUpdate(DocumentEvent$ElementChange, DocumentEvent, Shape, ViewFactory) line: 1172
      HTMLEditorKit$HTMLFactory$BodyBlockView(BoxView).forwardUpdate(DocumentEvent$ElementChange, DocumentEvent, Shape, ViewFactory) line: 241
      HTMLEditorKit$HTMLFactory$BodyBlockView(View).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 797
      HTMLEditorKit$HTMLFactory$BodyBlockView(BlockView).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 341
      BlockView(View).forwardUpdateToView(View, DocumentEvent, Shape, ViewFactory) line: 1241
      BlockView(View).forwardUpdate(DocumentEvent$ElementChange, DocumentEvent, Shape, ViewFactory) line: 1172
      BlockView(BoxView).forwardUpdate(DocumentEvent$ElementChange, DocumentEvent, Shape, ViewFactory) line: 241
      BlockView(View).changedUpdate(DocumentEvent, Shape, ViewFactory) line: 797
      BlockView.changedUpdate(DocumentEvent, Shape, ViewFactory) line: 341
      BasicTextUI$RootView.changedUpdate(DocumentEvent, Shape, ViewFactory) line: 1737
      BasicTextUI$UpdateHandler.changedUpdate(DocumentEvent) line: 1998
      HTMLDocument(AbstractDocument).fireChangedUpdate(DocumentEvent) line: 232
      HTMLDocument.fireChangedUpdate(DocumentEvent) line: 1763
      DefaultStyledDocument$ChangeUpdateRunnable.run() line: 2761
      InvocationEvent.dispatch() line: 313
      EventQueue.dispatchEventImpl(AWTEvent, Object) line: 770
      EventQueue$4.run() line: 721
      EventQueue$4.run() line: 715
      AccessController.doPrivileged(PrivilegedAction<T>, AccessControlContext) line: not available [native method]
      ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(PrivilegedAction<T>, AccessControlContext, AccessControlContext) line: 85
      EventQueue.dispatchEvent(AWTEvent) line: 740
      EventDispatchThread.pumpOneEventForFilters(int) line: 203
      EventDispatchThread.pumpEventsForFilter(int, Conditional, EventFilter) line: 124
      EventDispatchThread.pumpEventsForHierarchy(int, Conditional, Component) line: 113
      EventDispatchThread.pumpEvents(int, Conditional) line: 109
      EventDispatchThread.pumpEvents(Conditional) line: 101
      EventDispatchThread.run() line: 90


      REGRESSION : Last worked in version 11

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      This issue is very sensitive to system configuration and system performance level. It may to be easier to reproduce on slower CPUs, or on CPUs with lots of background CPU load.

      1 - Load example source code into Eclipse IDE (Java Photon)
      2 - Click Debug button to start program in debug session. If program window appears after launch, problem did not reproduce. If this happens, try clicking on Eclipse debug button several times (up to 5-10) in quick succession to launch multiple simultaneous instantiations of program.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      One program window should appear for each attempted launch of the program.

      ACTUAL -
      Some program launches may result in main thread and AWT Event Queue thread being locked and no window appearing.

      ---------- BEGIN SOURCE ----------
      package com.test;

      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Component;
      import java.awt.Container;
      import java.awt.Dimension;
      import java.awt.FlowLayout;
      import java.awt.Font;
      import java.awt.GridBagConstraints;
      import java.awt.GridBagLayout;
      import java.awt.Insets;
      import java.awt.event.ActionEvent;
      import java.awt.event.ActionListener;
      import java.awt.event.WindowEvent;
      import java.text.NumberFormat;
      import javax.swing.BorderFactory;
      import javax.swing.Box;
      import javax.swing.BoxLayout;
      import javax.swing.JButton;
      import javax.swing.JEditorPane;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.JPanel;
      import javax.swing.JTextArea;
      import javax.swing.JTextField;
      import javax.swing.SwingUtilities;
      import javax.swing.UIManager;
      import javax.swing.border.EtchedBorder;
      import javax.swing.event.ChangeEvent;
      import javax.swing.event.ChangeListener;

      public class Main extends JFrame {

      private testThreadLockPanel tstPanel;
      public static void main(String[] args) {
      new Main();
      }
        
      public Main() {

      //for (int i=0; i<0; i++) {
      // KeepCPUBusyThread t = new KeepCPUBusyThread();
      // t.start();
      //}
      //try { Thread.sleep(1000); } catch (InterruptedException e) {}

      tstPanel = new testThreadLockPanel();

      }

      //class KeepCPUBusyThread extends Thread {
      // public void run() {
      // float a;
      // for (int k = 0; k < 2; k++)
      // for (int j = 0; j < 500000000; j++)
      // for (int i = 0; i < 500000000; i++)
      // a = (i*j)/1000;
      // }
      //}

      private class testThreadLockPanel extends JFrame implements ActionListener {

      private JTextField displayScaleField = new JTextField(5);

      public testThreadLockPanel() {

      this.setTitle("Test Panel");
      setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
      setBackground(new Color (217, 227, 232));

      JPanel topPanel = new JPanel();
      topPanel.setBackground(new Color (217, 227, 232));
      topPanel.setOpaque(true);

      JPanel boxPanel = new JPanel();
      boxPanel.setOpaque(false);
      boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.Y_AXIS));
      boxPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory
      .createEmptyBorder(0, 0, 0, 0), BorderFactory
      .createEtchedBorder(EtchedBorder.LOWERED)));

      JPanel headerPanel = new JPanel();
      headerPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
      headerPanel.setBackground(new Color(171, 194, 211));
      headerPanel.setOpaque(true);
      JLabel text = new JLabel("Configure Display Scaling:", JLabel.LEFT);
      text.setFont(text.getFont().deriveFont(12.0f).deriveFont(Font.BOLD));
      headerPanel.add(text);
      boxPanel.add(headerPanel);

      NumberFormat nf = NumberFormat.getInstance(); // otherwise it's a decimal number eg 1.2
      nf.setMinimumFractionDigits(1);
      String text2 = "Display scaling can be used to increase the size of program windows and fonts for improved readability on high resolution displays. <br><br>By default, the scale is set automatically based on the display resolution. To override this behavior, enter a value below between " + nf.format(1.0) + " and " + nf.format(3.0) + ". To restore the default behavior, leave this field blank.";
      JEditorPane scalingMsgArea = new JEditorPane("text/html", text2);
      scalingMsgArea.setEditable(false);
      scalingMsgArea.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, Boolean.TRUE);
      scalingMsgArea.setFont(UIManager.getFont("Label.font").deriveFont(12.0f).deriveFont(Font.PLAIN));
      scalingMsgArea.setOpaque(false);
      scalingMsgArea.setBorder(
      BorderFactory.createEmptyBorder(25, 20, 10, 20));

      // uncomment sleep to let object setup complete, which prevents thread lock
      //try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); }

      boxPanel.add(scalingMsgArea);


      JPanel footerPanel = new JPanel();
      footerPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
      footerPanel.setBorder(
      BorderFactory.createEmptyBorder(10,20,10,20));
      footerPanel.setOpaque(false);
      JLabel text3 = new JLabel("Note: Changes do not take effect until the program is restarted.", JLabel.LEFT);
      text3.setFont(text3.getFont().deriveFont(12.0f).deriveFont(Font.PLAIN));
      footerPanel.add(text3);
      boxPanel.add(footerPanel);

      topPanel.add(boxPanel);
      boxPanel.setPreferredSize(new Dimension(520, 330));
      this.add(topPanel);
      this.pack();
      this.setLocationRelativeTo(null);
      this.setVisible(true);
      }

      protected void processWindowEvent(WindowEvent e) {
      if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
      }
      }
      public void actionPerformed(ActionEvent evt) { }
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Adding a Thread.sleep(50) after instantiation of JEditorPane object and before calling pack() seems to make it impossible to reproduce.

      FREQUENCY : often


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

              Created:
              Updated:
              Resolved: