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

REGRESSION: serious breakage in JTabbedPane.setComponentAt()

    XMLWordPrintable

Details

    • b57
    • x86
    • windows_xp

    Description



      Name: rl43681 Date: 03/29/2004


      FULL PRODUCT VERSION :
      java version "1.5.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32c)
      Java HotSpot(TM) Client VM (build 1.5.0-beta-b32c, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      The fix for bug #4668593 seriously breaks JTabbedPane.setComponentAt when HTML title are in use. There were two separate mistakes made during that bug fix:

      First, the __index_to_remove__ client property that was introduced is never removed. Event listeners triggered during a setComponentAt "see" this property, if it exists from an earlier remove, and take inappropriate actions. This can result in removing the HTML view for a tab, so that instead of the rendered HTML view you actually see the HTML source in the tab title.

      Second, the test "if (htmlViews != null && htmlViews.size()>=index) {" in BasicTabbedPaneUI is incorrect. It should be ">", not ">=" -- the ">=" results in an ArrayIndexOutOfBoundsException when htmlViews.size() == index.

      This worked in JDK 1.4.0 and 1.4.1.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the provided test case.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The test case will run without error.
      ACTUAL -
      The code generates an ArrayIndexOutOfBoundsException.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1 >= 1
              at java.util.Vector.removeElementAt(Unknown Source)
              at javax.swing.plaf.basic.BasicTabbedPaneUI$Handler.componentRemoved(Unknown Source)
              at java.awt.Container.processContainerEvent(Unknown Source)
              at java.awt.Container.processEvent(Unknown Source)
              at java.awt.Component.dispatchEventImpl(Unknown Source)
              at java.awt.Container.dispatchEventImpl(Unknown Source)
              at java.awt.Component.dispatchEvent(Unknown Source)
              at java.awt.Container.remove(Unknown Source)
              at javax.swing.JTabbedPane.setComponentAt(Unknown Source)
              at Test.main(Test.java:11)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class Test{
          public static void main(String[] arg) {
              javax.swing.JTabbedPane tabs = new javax.swing.JTabbedPane();
              tabs.addTab("<html>Test</html>", new javax.swing.JButton());
              tabs.addTab("Test2", new javax.swing.JButton());
              tabs.remove(1);
              
              // Workaround: uncomment this line and it will work
              //tabs.putClientProperty("__index_to_remove__", null);
              
              tabs.setComponentAt(0, new javax.swing.JButton());
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Remove the client property prior to calling setComponentAt:

      tabs.putClientProperty("__index_to_remove__", null);

      Release Regression From : 1.4.0_00
      The above release value was the last known release where this
      bug was known to work. Since then there has been a regression.

      (Incident Review ID: 245178)
      ======================================================================

      Attachments

        Activity

          People

            draskinsunw Daniel Raskin (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: