On occasions I will get the following exception thrown whenever I happen to be using SimpleBrowser.this.processor.processTask() method to run a SwingWorker<Void, Void>-based class Task worker thread (within doInBackground()) :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at javax.swing.text.BoxView.getOffset(BoxView.java:1076)
at javax.swing.text.BoxView.childAllocation(BoxView.java:670)
at javax.swing.text.CompositeView.getChildAllocation(CompositeView.java:215)
at javax.swing.text.BoxView.getChildAllocation(BoxView.java:428)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.calculateViewPosition(BasicTextUI.java:1978)
at javax.swing.plaf.basic.BasicTextUI$UpdateHandler.layoutContainer(BasicTextUI.java:1954)
at java.awt.Container.layout(Container.java:1432)
at java.awt.Container.doLayout(Container.java:1421)
at java.awt.Container.validateTree(Container.java:1519)
at java.awt.Container.validateTree(Container.java:1526)
at java.awt.Container.validateTree(Container.java:1526)
at java.awt.Container.validate(Container.java:1491)
at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:639)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:127)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
I haven't found much reliable online information to illustrate this issue any further so I'm a bit in the dark. Following is my code that runs within the aforementioned worker thread which I believe throws the exception:
/**
* Use {@link #setWebBrowserURL} using a local {@link com.ppowell.tools.ObjectTools.SwingTools.Task}
*/
protected void processTask() {
Task task = new Task() {
public Void doInBackground() {
int progress = 0;
while (!SimpleBrowser.this.builder.hasLoadedWebpage && progress < 100) {
SimpleBrowser.this.statusBar.setMessage("Attempting to load " + SimpleBrowser.this.getURL().toString());
this.setProgress(progress);
progress++;
}
SimpleBrowser.this.setWebBrowserURL();
try {
Thread.sleep(2500);
} catch (InterruptedException ignore) {} // DO NOTHING
if (SimpleBrowser.this.builder.hasLoadedWebpage) {
SimpleBrowser.this.statusBar.setMessage("Done");
}
return null;
}
};
task.addPropertyChangeListener(SimpleBrowser.this);
task.execute();
}
Is there a way I might at least be able to suppress this error (the GUI application browser functions just fine in spite of it), or, even better, solve this inconsistent problem?
Thanks
Phil