can't find the problem with java.lang.ArrayIndexOutOfBoundsException - java

i have a problem with my application tha some times return this error in console, but i can't find the origin (all Unknown Source). THe application seems to work properly after this error, but i want to understand what appening... How i can do?
Thank you and sorry for my english!
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.getPreferredSize(Unknown Source)
at javax.swing.JComponent.getPreferredSize(Unknown Source)
at javax.swing.ScrollPaneLayout.layoutContainer(Unknown Source)
at java.awt.Container.layout(Unknown Source)
at java.awt.Container.doLayout(Unknown Source)
at java.awt.Container.validateTree(Unknown Source)
at java.awt.Container.validate(Unknown Source)
at javax.swing.RepaintManager.validateInvalidComponents(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

Looking at the source of BasicListUI.updateLayoutState(), this can only happen when the list being displayed changes size while the method executes.
The most likely reason is that you're modifying the model from outside the event dispatch thread. This is a serious problem, since it could result in all kinds of bizarre behaviour and even corrupt data.
To fix them problem, use SwingUtilities.invokeLater() whenever you need to manipulate the model from outside the EDT.

This type of error is sometimes caused by updating GUI components off the EDT, when it should be done on the EDT.
If fixing any code that violates that principle does not solve the problem, I suggest you try to prepare an SSCCE & post it to the thread.

Related

How to find an (informative) stack trace of unknown exception thrown by Swing components

I have setup an UncaughtExceptionHandler in my Swing app which will catch and log any uncaught exceptions in my code and report them to me. The stack traces for most of these errors are helpful in diagnosing the issues. However, sometimes I get a problem like this:
Thread : AWT-EventQueue-2
Thread[AWT-EventQueue-2,6,javawsApplicationThreadGroup]
Error Message:
java.lang.Double cannot be cast to java.lang.Integer
Error String:
java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
StackTrace: class java.lang.ClassCastException
java.lang.Integer.compareTo(Unknown Source)
javax.swing.table.TableRowSorter$ComparableComparator.compare(Unknown Source)
javax.swing.DefaultRowSorter.compare(Unknown Source)
javax.swing.DefaultRowSorter.access$100(Unknown Source)
javax.swing.DefaultRowSorter$Row.compareTo(Unknown Source)
javax.swing.DefaultRowSorter$Row.compareTo(Unknown Source)
java.util.ComparableTimSort.binarySort(Unknown Source)
java.util.ComparableTimSort.sort(Unknown Source)
java.util.Arrays.sort(Unknown Source)
javax.swing.DefaultRowSorter.sortExistingData(Unknown Source)
javax.swing.DefaultRowSorter.setSortKeys(Unknown Source)
javax.swing.DefaultRowSorter.toggleSortOrder(Unknown Source)
javax.swing.plaf.basic.BasicTableHeaderUI$MouseInputHandler.mouseClicked(Unknown Source)
java.awt.AWTEventMulticaster.mouseClicked(Unknown Source)
java.awt.Component.processMouseEvent(Unknown Source)
javax.swing.JComponent.processMouseEvent(Unknown Source)
java.awt.Component.processEvent(Unknown Source)
java.awt.Container.processEvent(Unknown Source)
java.awt.Component.dispatchEventImpl(Unknown Source)
java.awt.Container.dispatchEventImpl(Unknown Source)
java.awt.Component.dispatchEvent(Unknown Source)
java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
java.awt.Container.dispatchEventImpl(Unknown Source)
java.awt.Window.dispatchEventImpl(Unknown Source)
java.awt.Component.dispatchEvent(Unknown Source)
java.awt.EventQueue.dispatchEventImpl(Unknown Source)
java.awt.EventQueue.access$500(Unknown Source)
java.awt.EventQueue$3.run(Unknown Source)
java.awt.EventQueue$3.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
java.awt.EventQueue$4.run(Unknown Source)
java.awt.EventQueue$4.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
java.awt.EventQueue.dispatchEvent(Unknown Source)
java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
java.awt.EventDispatchThread.pumpEvents(Unknown Source)
java.awt.EventDispatchThread.pumpEvents(Unknown Source)
java.awt.EventDispatchThread.run(Unknown Source)
I don't need help diagnosing this particular problem, the problem is clear (the user is trying to sort a JTable somewhere in the application, but the values in that column are Doubles, but the table declaration said to expect Integers). However, I have no idea by this stack trace which JTable is the source of the problem (and there are a LOT of tables in my app). Without knowing WHERE the problem is coming from, I have no way of fixing it.
So, is there any more useful debugging information I can obtain to help find the source of this problem and others like it?
Note: it's not just the fact that every line says "Unknown source," because none of the classes listed in the stack trace are my classes, they are all library classes. So even if they gave a line number to the problem, it would be to a class I cannot fix.
In cases like this I override something just to add debugging info. For example in this case, we see in the stack trace that DefaultRowSorter.setSortKeys was called, so we could use a class
public class MyRowSorter<M, I> extends DefaultRowSorter<M, I> {
....
#Override
public void setSortKeys(List<? extends SortKey> sortKeys) {
try {
super.setSortKeys(sortKeys);
} catch (Exception e) {
//
// print debugging info here!
//
throw e;
}
}
}
Now you can set MyRowSorter to sort your tables, add the necessary debugging info to MyRowSorter, and you can debug which table had the problem.

Problems in running I/O in EDT of applet

Our applet source code is kind of spaghetti (written in 2000, Java 1.3 then) and we want to recompile it to Java 1.6 or 1.7.
When I'm testing it, most of the Swing is OK but after sometime, an Exception occurred, which is EDT exception. Specifically, when a drag event is done, a series of EDT exceptions appear.
Is this something to with coding the I/O part in ActionListeners because I've read that it is bad to code I/O operations in action listeners, which EDT executes when a action is performed.
EDIT:
This is the recurring exception
Exception in thread "AWT-EventQueue-3" java.lang.NullPointerException
at javax.swing.BufferStrategyPaintManager.flushAccumulatedRegion(Unknown Source)
at javax.swing.BufferStrategyPaintManager.copyArea(Unknown Source)
at javax.swing.RepaintManager.copyArea(Unknown Source)
at javax.swing.JViewport.blitDoubleBuffered(Unknown Source)
at javax.swing.JViewport.windowBlitPaint(Unknown Source)
at javax.swing.JViewport.setViewPosition(Unknown Source)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(Unknown Source)
at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.fireStateChanged(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.setRangeProperties(Unknown Source)
at javax.swing.DefaultBoundedRangeModel.setValue(Unknown Source)
at javax.swing.JScrollBar.setValue(Unknown Source)
at javax.swing.plaf.basic.BasicScrollBarUI$TrackListener.setValueFrom(Unknown Source)
at javax.swing.plaf.basic.BasicScrollBarUI$TrackListener.mouseDragged(Unknown Source)
at java.awt.Component.processMouseMotionEvent(Unknown Source)
at javax.swing.JComponent.processMouseMotionEvent(Unknown Source)
at java.awt.Component.processEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I guess it has something to do with the version of java plugin.
In java 1.6_10, a new version of this plugin is release, i just disabled the option in java found in control panel
Advance->Java Plug In ->Enable the next generation Java Plug in
When i disable this, this recurring error with no distinct behavior no longer appears.
I guess also it has something to do with our code written in the days of Java 1.3.

Can't find the source of an exception in Java

Basically an exception is being thrown and I can't find the reason. Here is what I get on the console:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 0
at org.apache.batik.gvt.renderer.StrokingTextPainter.computeTextRuns(Unknown Source)
at org.apache.batik.gvt.renderer.StrokingTextPainter.getTextRuns(Unknown Source)
at org.apache.batik.gvt.renderer.StrokingTextPainter.getOutline(Unknown Source)
at org.apache.batik.gvt.renderer.BasicTextPainter.getGeometryBounds(Unknown Source)
at org.apache.batik.gvt.TextNode.getGeometryBounds(Unknown Source)
at org.apache.batik.gvt.TextNode.getSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.AbstractGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getTransformedSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.getSensitiveBounds(Unknown Source)
at org.apache.batik.gvt.CompositeGraphicsNode.nodeHitAt(Unknown Source)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchMouseEvent(Unknown Source)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchEvent(Unknown Source)
at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown Source)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.mouseEntered(Unknown Source)
at org.apache.batik.swing.gvt.AbstractJGVTComponent$Listener.dispatchMouseEntered(Unknown Source)
at org.apache.batik.swing.svg.AbstractJSVGComponent$SVGListener.dispatchMouseEntered(Unknown Source)
at org.apache.batik.swing.gvt.AbstractJGVTComponent$Listener.mouseEntered(Unknown Source)
at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
at java.awt.AWTEventMulticaster.mouseEntered(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(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.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.trackMouseEnterExit(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$400(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
It is obviously from a batik lib that I use to paint SVG files, but I made sure that nothing is painted until the document is loaded, ready and showing on screen. When thrown nothing is painted.
Another interesting thing is the timing of the throwing. I am unable to find any logical patern, as sometimes it is thrown as soon as I initiate the class and sometimes it needs more then five minutes. In addition to this, as far as I tested there is no single action that calls repaint() that triggers it or rather all do.
I am new to Java and all the other exceptions had the class and row number of where they were thrown so I don't know what to do here.
Any suggestions would be greatly appreciated.
The code is enormous so I'll put just the paint method and if anything additional is needed please say so.
#Override
public void paint(Graphics g) {
if(documentLoaded && showingOnScreen){
try{
rad = (int)(radInit+zoom*faktorRad); //max rad = 20
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
paintElements(g2d);
}
catch(NullPointerException nulle){
}
}
}
edit: There is no array in my class so i can't check any index. I think that this exception is thrown from a library I use, but it's a .jar file and I don't know how to open it or if I can.
It appears that the exception is thrown after a "mouse entered" event while the library is attempting to calculate something about the geometry. None of the classes in the stack trace appear to be listeners you have defined. I'm afraid I don't know anything about this library, but I suggest you go through the UI you have defined for things that aren't quite right, or even just things that you can remove and attempt to reproduce the problem. It looks like either something is wrong with the rendered geometry or the listener is getting called before it is supposed to, and depends on rendering that has not happened yet.

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 15

So I'm getting this kind of obscure error, and I don't know what it means. Without viewing my code, can someone tell me what causes this error and possible solutions to this error? Any help would be greatly appreciated.
Here is the error:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: No such child: 15
at java.awt.Container.getComponent(Unknown Source)
at javax.swing.JComponent.rectangleIsObscured(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.access$700(Unknown Source)
at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Without seeing any code, or any SSCCE which illustrates the issue we can basically only guess what is going on. My bet would be you are messing with your Swing components on another Thread, and the ArrayIndexOutOfBoundsException is a result of removing components on the wrong thread.
In order to debug this, I would start by using the CheckThreadViolationRepaintManager and fix any errors it indicates.
If this does not work, I would try putting a breakpoint for the ArrayIndexOutOfBoundsException, see which container causes the error and try to put breakpoints for any add and remove method on it to determine who removes the component causing the exception (probably on the wrong thread, which you can easily check with the EventQueue.isDispatchThread() method )
if you are using swing use worker threads to control the components worker thread tutorial

java: IllegalStateException - Buffers have not been created

I have a weird exception in one my servers.
The same application (java, swing ) runs on several servers.
Each server runs with dual monitors.
Same jre version (jre 6 version 24)
All of them in a decent CPU/memory consumption.
In only one of them - when I drag my app from one monitor to the other it throws a java.lang.IllegalStateException exception. I have attached the full exception below.
Does anyone have any idea ?
Thank you.
And now, behold, the exception :
java.lang.IllegalStateException: Buffers have not been created
at sun.awt.windows.WComponentPeer.getBackBuffer(Unknown Source)
at java.awt.Component$FlipBufferStrategy.getBackBuffer(Unknown Source)
at java.awt.Component$FlipBufferStrategy.updateInternalBuffers(Unknown Source)
at java.awt.Component$FlipBufferStrategy.revalidate(Unknown Source)
at java.awt.Component$FlipBufferStrategy.revalidate(Unknown Source)
at java.awt.Component$FlipBufferStrategy.getDrawGraphics(Unknown Source)
at javax.swing.BufferStrategyPaintManager.prepare(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Try adding the following parameter to your java command line:
-Dsun.java2d.d3d=false
having tried the following,
-Dsun.java2d.d3d=false
-Dsun.java2d.noddraw=true
-Dsun.java2d.ddoffscreen=false
-DJ2D_D3D=false
and NOT finding a solution, i stumbled on this which worked.
jframe.createBufferStrategy(1);
http://www.java-gaming.org/index.php/topic,25021.0
This is the case in the Oracle bug database: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6933331.
From the bug evaluation:
.. has no consequences other
than a stack trace dump in a console (no hang, no visual artifacts were reported)

Categories

Resources