JDK-6873554 : BasicTabbedPaneUI is creating htmlViews even when html is not used
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6u16
  • Priority: P5
  • Status: Closed
  • Resolution: Cannot Reproduce
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2009-08-19
  • Updated: 2022-03-09
  • Resolved: 2022-03-09
Related Reports
Relates :  
Description
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

Does this problem occur on J2SE 5.0.x or 6.0?  Yes / No (pick one)
Yes

Operating System Configuration Information (be specific):
Client: Microsoft Windows XP [Version 5.1.2600]

Bug Description:
BasicTabbedPaneUI is creating htmlViews even when html is not used

The JavaDoc for BasicTabbedPaneUI says 'The Views (one per tab title requiring HTML
rendering) are stored in the htmlViews Vector, which is only allocated after
the first time we run into an HTML tab.' However the code below demonstrates 
that htmlViews are created even when there are no HTML Tabs.

Expected: this code to run forever
Actual: eventually an OutOfMemoryError is thrown (due to the htmlViews which 
should never have been created in the first place getting bigger  every call
 to setTitleAt - which is related to bug 6670274)

import javax.swing.*;

public class Test {
  public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        boolean firstTitle = true;
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab("Title 1", new JLabel("Component"));
        tabbedPane.updateUI();
        while (true) {
          firstTitle = !firstTitle;
          tabbedPane.setTitleAt(0, firstTitle ? "Title 1" : "Title 2");
        }
      }
    });
  }
}


}

Comments
PUBLIC COMMENTS The test is not failed on 1.6.0_16-b01. But the javadoc of the javax.swing.plaf.basic.BasicTabbedPaneUI.Handler#componentAdded should correspondent to actual behavior: htmlViews is created once with all Views (see the javax.swing.plaf.basic.BasicTabbedPaneUI#createHTMLVector method implementation)
18-08-2010