Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 4129682
Votes 0
Synopsis Stylepad example: Inserting text at position 0 a second time cause a Exception
Category java:classes_swing
Reported Against swing1.0.2
Release Fixed
State 11-Closed, duplicate of 4128967, bug
Priority: 4-Low
Related Bugs 4128967
Submit Date 16-APR-1998
Description




In the Stylepad example included in swing-1.0.1
if the user places the Caret in position 0
(the start of the document) and insert some text
and then moves the cuser back to position 0 and
tries to insert some more text a Exception is
thrown.

The error has been reproduced with jdk 1.1.5
and swing 1.0.1 under Windows 95 and 
Swing-1.0.1 with JDK 1.1.5 on Windows NT 4 and
Swing-1.0.1 with JDK 1.1.5 on Unix
So its looks like its not a Platform dependant
problem.


----
I have also included some example code that will 
reproduce the problem

import java.awt.BorderLayout;

import com.sun.java.swing.JTextPane;
import com.sun.java.swing.JPanel;

public class TestJTextPane extends JPanel
{
   
   protected JTextPane editor = new JTextPane();
   
   public TestJTextPane()
   {
      super();
      
      setLayout(new BorderLayout());
      
      add("Center", editor);
      
   }
   
   public void reproduceException()
   {
      try
      {
         editor.getDocument().insertString(0, "String1", null);
         
         // uncomment this line to produce the Exception
         //editor.getDocument().insertString(0, "String2", null);
         
      } catch (com.sun.java.swing.text.BadLocationException e)
      {}
   }
   
   static public void main(String[] args)
   {
      java.awt.Frame testFrame = new java.awt.Frame("Test for JTextPane");
      
      TestJTextPane testEditorPane = new TestJTextPane();
      testFrame.add("Center", testEditorPane);
      testFrame.pack();
      testFrame.setSize(700, 500);
      testFrame.show(); 
      testEditorPane.reproduceException();
      
   }
}



Exception occurred during event dispatching:
com.sun.java.swing.text.StateInvariantError: infinite loop in formatting
        at
com.sun.java.swing.text.ParagraphView.rebuildRows(ParagraphView.java:163)
        at
com.sun.java.swing.text.ParagraphView.layout(ParagraphView.java:127)
        at
com.sun.java.swing.text.ParagraphView.insertUpdate(ParagraphView.java:596)
        at
com.sun.java.swing.text.BoxView.insertUpdate(BoxView.java:311)
        at
com.sun.java.swing.text.DefaultTextUI$RootView.insertUpdate(DefaultTextUI.java:834)
        at
com.sun.java.swing.text.DefaultTextUI$UpdateHandler.insertUpdate(DefaultTextUI.java:1050)
        at
com.sun.java.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:137)
        at
com.sun.java.swing.text.AbstractDocument.insertString(AbstractDocument.java:415)
        at
com.sun.java.swing.JTextPane.replaceSelection(JTextPane.java:148)
        at
com.sun.java.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:650)
        at
com.sun.java.swing.text.JTextComponent.processComponentKeyEvent(JTextComponent.java:1026)
        at
com.sun.java.swing.JComponent.processKeyEvent(JComponent.java:1256)
        at java.awt.Component.processEvent(Component.java:2138)
        at java.awt.Container.processEvent(Container.java:894)
        at java.awt.Component.dispatchEventImpl(Component.java:1764)
        at java.awt.Container.dispatchEventImpl(Container.java:939)
        at java.awt.Component.dispatchEvent(Component.java:1704)
        at
java.awt.LightweightDispatcher.processKeyEvent(Container.java:1416)
        at
java.awt.LightweightDispatcher.dispatchEvent(Container.java:1402)
        at java.awt.Container.dispatchEventImpl(Container.java:926)
        at java.awt.Window.dispatchEventImpl(Window.java:443)
        at java.awt.Component.dispatchEvent(Component.java:1704)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:63)

A intresting twist with this problem that might help you track it down
is that if more than one line of text is inserted into the JTextPane
it takes three inerts at possition 0 to cause the exception.

import java.awt.BorderLayout;

import com.sun.java.swing.JTextPane;
import com.sun.java.swing.JPanel;

public class TestJTextPane extends JPanel
{
   
   protected JTextPane editor = new JTextPane();
   
   public TestJTextPane()
   {
      super();
      
      setLayout(new BorderLayout());
      
      add("Center", editor);
      
   }
   
   public void reproduceException()
   {
      try
      {
         editor.getDocument().insertString(0, "String1" + '\n', null);
         editor.getDocument().insertString(0, "String2", null);
         
         // uncomment this line to produce the Exception
         //editor.getDocument().insertString(0, "String3", null);
         
      } catch (com.sun.java.swing.text.BadLocationException e)
      {}
   }
   
   static public void main(String[] args)
   {
      java.awt.Frame testFrame = new java.awt.Frame("Test for JTextPane");
      
      TestJTextPane testEditorPane = new TestJTextPane();
      testFrame.add("Center", testEditorPane);
      testFrame.pack();
      testFrame.setSize(700, 500);
      testFrame.show(); 
      testEditorPane.reproduceException();
      
   }
}
(Review ID: 28272)
======================================================================
Work Around




Noe, but would be very greatfull if any one
could provide one.
======================================================================
Evaluation
N/A
Comments
  
  Include a link with my name & email   


PLEASE NOTE: JDK6 is formerly known as Project Mustang