Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is a StateInvariantError (in JTextPAne)?

11 views
Skip to first unread message

Michael Welsh Duggan

unread,
Apr 10, 2001, 1:42:21 PM4/10/01
to
We are trying to develop a text editor that finds 'bad' English text
and highlights it. Our code first creates a JTextPane, fills it with
text, and then marks up the text. The code is too large to include
here, so I'll post up the relevant snippets.

The contents of the JTextPane are as follows: "t. x"

The routine that marks up the text pane, after the text has been
inserted is as follows:

private StyledDocument document;

private void addMarkup(final SimpleAttributeSet attribute,
final int offset, final int length) {
System.out.println("START: " + offset + " LENGTH: " + length + " ATTRIBUTE: " + attribute);
try {javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
document.setCharacterAttributes( offset, length, attribute, false);
}});} catch (Exception e) {System.err.println(e);}
}

When run, the program generates the following output:

...
START: 0 LENGTH: 2 ATTRIBUTE: foreground=java.awt.Color[r=255,g=0,b=0]
START: 3 LENGTH: 2 ATTRIBUTE: foreground=java.awt.Color[r=0,g=0,b=0]
Exception occurred during event dispatching:
javax.swing.text.StateInvariantError: infinite loop in formatting
at javax.swing.text.FlowView$FlowStrategy.layout(FlowView.java:429)
at javax.swing.text.FlowView.layout(FlowView.java:182)
at javax.swing.text.BoxView.setSize(BoxView.java:265)
at javax.swing.text.BoxView.layout(BoxView.java:600)
at javax.swing.text.BoxView.setSize(BoxView.java:265)
at javax.swing.plaf.basic.BasicTextUI$RootView.setSize(BasicTextUI.java:1450)
at javax.swing.plaf.basic.BasicTextUI.getPreferredSize(BasicTextUI.java:688)
at javax.swing.JComponent.getPreferredSize(JComponent.java:1042)
at javax.swing.JEditorPane.getPreferredSize(JEditorPane.java:1065)
at javax.swing.ScrollPaneLayout.layoutContainer(ScrollPaneLayout.java:752)
at java.awt.Container.layout(Container.java:686)
at java.awt.Container.doLayout(Container.java:676)
at java.awt.Container.validateTree(Container.java:750)
at java.awt.Container.validate(Container.java:728)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:313)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:204)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:154)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:317)
at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:103)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
...

Several other StateInvariantError's are thrown, and the program
eventually freezes.

We can't figure out how to avoid or work around these
StateInvariantError's, and they don't appear in the java
documentation. What are they, and how to we avoid them?

--
Michael Duggan
(md...@cs.cmu.edu)

Jim Sculley

unread,
Apr 10, 2001, 3:11:06 PM4/10/01
to
Michael Welsh Duggan wrote:
>
> We are trying to develop a text editor that finds 'bad' English text
> and highlights it. Our code first creates a JTextPane, fills it with
> text, and then marks up the text. The code is too large to include
> here, so I'll post up the relevant snippets.
>
> The contents of the JTextPane are as follows: "t. x"
>
> The routine that marks up the text pane, after the text has been
> inserted is as follows:

<code and stack trace snipped>

>
> Several other StateInvariantError's are thrown, and the program
> eventually freezes.
>
> We can't figure out how to avoid or work around these
> StateInvariantError's, and they don't appear in the java
> documentation. What are they, and how to we avoid them?

The setCharacterAttributes() method fires a DefaultDocumentEvent as
specified in the documentation. If you are calling addMarkup() as a
result of some DocumentEvent, the result will be an infinite loop.

Jim S.

0 new messages