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

Hierarchical composition of JTextPanes causes ArrayIndexOutOfBoundsException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.1, 1.4.1_03, 1.4.2
    • client-libs
    • x86
    • windows_2000, windows_xp



      Name: jk109818 Date: 07/08/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)


      FULL OS VERSION :
      Microsoft Windows XP [Version 5.1.2600] professional


      A DESCRIPTION OF THE PROBLEM :
      I use three JTextPane with an hierarchically structure.
      JTextPane 1 contains JTextPane 2 and JTextPane 2 contains JTextPane3 (or an
      other JComponent with the same result).

      Now if I set the cursor (by mouse navigation) in the JTextPane2 directly behind the JTextPane3 component and make an input, I'll get an exception (java.lang.ArrayIndexOutOfBoundsException: No such child: 0) and the input does not appear. If the JTextPane2 has lost the focus, the input appears.

      If I set text at the same position by calling insertString(...) bovore the components are showed, no exception occures. If I set text in the same way after the components are showed, the excepton occures.

      The exception generally occures only when a character is set at the first position after JTextPane2. Setting characters behind works.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and start the demo.

      Set the cursor after the green JTextPane 3 and type any character.
      You can see the exception thrown. Let the component loose the focus, you
      can see the character you typed.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The typed character should be occure and no exception.

      ACTUAL -
      The exception and not the typed character.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.ArrayIndexOutOfBoundsException: No such child: 0
              at java.awt.Container.getComponent(Container.java:237)
              at javax.swing.text.ComponentView$Invalidator.cacheChildSizes(ComponentView.java:399)
              at javax.swing.text.ComponentView$Invalidator.doLayout(ComponentView.java:383)
              at java.awt.Container.validateTree(Container.java:1089)
              at java.awt.Container.validate(Container.java:1064)
              at javax.swing.text.ComponentView$Invalidator.validateIfNecessary(ComponentView.java:394)
              at javax.swing.text.ComponentView$Invalidator.getAlignmentY(ComponentView.java:442)
              at javax.swing.text.ComponentView.getAlignment(ComponentView.java:203)
              at javax.swing.text.BoxView.baselineRequirements(BoxView.java:1000)
              at javax.swing.text.ParagraphView$Row.calculateMinorAxisRequirements(ParagraphView.java:829)
              at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
              at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
              at javax.swing.text.BoxView.calculateMajorAxisRequirements(BoxView.java:849)
              at javax.swing.text.BoxView.checkRequests(BoxView.java:908)
              at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
              at javax.swing.text.BoxView.calculateMajorAxisRequirements(BoxView.java:849)
              at javax.swing.text.BoxView.checkRequests(BoxView.java:908)
              at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
              at javax.swing.plaf.basic.BasicTextUI$RootView.getMinimumSpan(BasicTextUI.java:1253)
              at javax.swing.plaf.basic.BasicTextUI.getMinimumSize(BasicTextUI.java:834)
              at javax.swing.JComponent.getMinimumSize(JComponent.java:1356)
              at javax.swing.text.ComponentView$Invalidator.cacheChildSizes(ComponentView.java:400)
              at javax.swing.text.ComponentView$Invalidator.doLayout(ComponentView.java:383)
              at java.awt.Container.validateTree(Container.java:1089)
              at java.awt.Container.validate(Container.java:1064)
              at javax.swing.text.ComponentView$Invalidator.validateIfNecessary(ComponentView.java:394)
              at javax.swing.text.ComponentView$Invalidator.getPreferredSize(ComponentView.java:427)
              at javax.swing.text.ComponentView.getPreferredSpan(ComponentView.java:119)
              at javax.swing.text.FlowView$LogicalView.getPreferredSpan(FlowView.java:638)
              at javax.swing.text.FlowView.calculateMinorAxisRequirements(FlowView.java:214)
              at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
              at javax.swing.text.BoxView.getMinimumSpan(BoxView.java:542)
              at javax.swing.text.BoxView.calculateMinorAxisRequirements(BoxView.java:881)
              at javax.swing.text.BoxView.checkRequests(BoxView.java:913)
              at javax.swing.text.BoxView.setSpanOnAxis(BoxView.java:325)
              at javax.swing.text.BoxView.layout(BoxView.java:682)
              at javax.swing.text.BoxView.setSize(BoxView.java:379)
              at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1598)
              at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:800)
              at javax.swing.JComponent.getPreferredSize(JComponent.java:1272)
              at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1206)
              at java.awt.GridBagLayout.GetLayoutInfo(GridBagLayout.java:892)
              at java.awt.GridBagLayout.getLayoutInfo(GridBagLayout.java:806)
              at java.awt.GridBagLayout.ArrangeGrid(GridBagLayout.java:1373)
              at java.awt.GridBagLayout.arrangeGrid(GridBagLayout.java:1336)
              at java.awt.GridBagLayout.layoutContainer(GridBagLayout.java:706)
              at java.awt.Container.layout(Container.java:1017)
              at java.awt.Container.doLayout(Container.java:1007)
              at java.awt.Container.validateTree(Container.java:1089)
              at java.awt.Container.validateTree(Container.java:1096)
              at java.awt.Container.validateTree(Container.java:1096)
              at java.awt.Container.validateTree(Container.java:1096)
              at java.awt.Container.validate(Container.java:1064)
              at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353)
              at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
              at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
              at java.awt.EventQueue.dispatchEvent(EventQueue.java:448)
              at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
              at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
              at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
              at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)



      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      import java.awt.*;
      import javax.swing.*;
      import javax.swing.text.*;

      public class TestBUG extends javax.swing.JFrame {
              
          public TestBUG() {
              initComponents();
              try{
                  // inner2 contains the number of the headline
                  JTextPane inner2 = new JTextPane(new DefaultStyledDocument());
                  inner2.setContentType("text/rtf");
                  inner2.setBackground( Color.green );
                  inner2.setAlignmentY(0.78f);
                  inner2.getDocument().insertString(0, "1.0", null);
                  inner2.setMaximumSize( new Dimension(30, 20) ); // same result if line absent
                  
                  // inner1 contains inner2 and the user input for the headline text
                  JTextPane inner1 = new JTextPane(new DefaultStyledDocument());
                  inner1.setContentType("text/rtf");
                  inner1.setBackground( Color.yellow );
                  
                  inner1.insertComponent(inner2); // same result when insert the component with insertString(...)
                  jTextPane0.insertComponent(inner1);
              }
              catch(Exception e){
                  e.printStackTrace();
              }
          }
          
          private void initComponents() {
              java.awt.GridBagConstraints gridBagConstraints;
              rootPanel = new javax.swing.JPanel();
              jTextPane0 = new javax.swing.JTextPane();
              getContentPane().setLayout(new java.awt.GridBagLayout());
              setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
              addWindowListener(new java.awt.event.WindowAdapter() {
                  public void windowClosing(java.awt.event.WindowEvent evt) {
                      exitForm(evt);
                  }
              });
              rootPanel.setLayout(new java.awt.GridBagLayout());
              rootPanel.setPreferredSize(new java.awt.Dimension(300, 300));
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              rootPanel.add(jTextPane0, gridBagConstraints);
              gridBagConstraints = new java.awt.GridBagConstraints();
              gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
              gridBagConstraints.weightx = 1.0;
              gridBagConstraints.weighty = 1.0;
              getContentPane().add(rootPanel, gridBagConstraints);
              pack();
          }

          private void exitForm(java.awt.event.WindowEvent evt) {
              System.exit(0);
          }
            
          public static void main(String args[]) {
              new TestBUG().show();
          }
          
          private javax.swing.JPanel rootPanel;
          private javax.swing.JTextPane jTextPane0;
         
      }


      ---------- END SOURCE ----------
      (Review ID: 185300)
      ======================================================================

            peterz Peter Zhelezniakov
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: