NullPointerException at javax.swing.plaf.basic.BasicTableUI$Handler.setValueIsAdjusting

I've been battling the NPE below for some months now; it cannot be reproduced on demand, but occurs often enough. My biggest problem is that I can't seem to figure out what is going wrong (using jre1.5.0_5, code below the exception) and have to resort to this uninviting post, hoping someone can can shed a light here.

The exeption is:

        at javax.swing.plaf.basic.BasicTableUI$Handler.setValueIsAdjusting(
        at javax.swing.plaf.basic.BasicTableUI$Handler.adjustFocusAndSelection(
        at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(
        at java.awt.AWTEventMulticaster.mousePressed(
        at java.awt.Component.processMouseEvent(
        at javax.swing.JComponent.processMouseEvent(
        at org.tbee.swing.table.JTableForEdit.processMouseEvent(
        at java.awt.Component.processEvent(
        at java.awt.Container.processEvent(
        at java.awt.Component.dispatchEventImpl(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.LightweightDispatcher.retargetMouseEvent(
        at java.awt.LightweightDispatcher.processMouseEvent(
        at java.awt.LightweightDispatcher.dispatchEvent(
        at java.awt.Container.dispatchEventImpl(
        at java.awt.Window.dispatchEventImpl(
        at java.awt.Component.dispatchEvent(
        at java.awt.EventQueue.dispatchEvent(
        at org.tbee.swing.StandardComponentPopupMenu.dispatchEvent(
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(
        at java.awt.EventDispatchThread.pumpEvents(
        at java.awt.EventDispatchThread.pumpEvents(

Now, after unpacking the in the jdk1.5.0_05 and looking at the line 882 it turns out to be the method declaration:

882:    protected void setValueIsAdjusting(boolean flag) {

But looking at the body, I expect either getSelectionModel being the culprit.

Now to finding the reason why: I first assume it is something I do in handling the mouse event. In the stack trace I find two pieces of code I made (both are from a swing library I maintain):




StandardComponentPopupMenu is a custom class to get standard popup menu's on several components, for example "copy" on text components or "select all rows" on tables. It is hooked into the system event queue (with thanks to Santhosh Kumar):


The line in the exception shows that the logic of the component has not been executed yet, since it first processes the event normally:

      protected void dispatchEvent(AWTEvent event)
            // handle regularly
98:            super.dispatchEvent(event);

JTableForEdit is a JTable extend which tries to make data entry go more like it does in MSAccess. The method in the trace does nothing more than detect if the last action was a keystroke or a mouse thing.

      protected void processMouseEvent(MouseEvent e)
            // remember keystroke
            iLastKeyStroke = null;
            // done

Both pieces of code do not give any reason why this would NPE. Unfortunately both classes are very relevant to the application, so I cannot deactivate them to see if the NPE doesn't occur any more.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

objectsConnect With a Mentor Commented:
yes, many moons ago we produced a patched swing jar that added an assert to methods for tracking down these sorts of problems. aspects may well be able to handle doing similiar.

Sorry I can't give you anything more concrete, but tracking down gui bugs that are not reproduceable can be a real pain and I'm not aware of any silver bullets.
Mayank SAssociate Director - Product EngineeringCommented:
>> jdk1.5.0_05

I am not sure how stable that is - I would use 1.5.0_06
make sure you aren't making *any* calls in your code that update the gui from a thread other than the event dispatch thread.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

tbeernotAuthor Commented:
@objects: this might very well be possible, it is a rather large and multithreading ERP application, so slipping "the thread" could be present somewhere. What thread crossing could cause this NPE?
Swing is single threaded such that any calls that affect the gui need to be made from the EDT.
Breaking this rule can result in indeterminite behaviour.
tbeernotAuthor Commented:
I know, but such a generic statement does not give much handle on the problem. I need a way to find the culprit that causes the NPE to be set up.
there is no easy way sorry. Adding asserts anywhere in your code that updates the gui to check your on the correct thread would be a good start.
In your case anything updating the table would seem a good place to start.

But the problem could be caused by something different, if you can create a small example that demonstrates it it may be worth submitting to Sun as a bug.
tbeernotAuthor Commented:
I'll settle for finding the cause :-)

I've been thinking about using AspectJ to handle some of my swing issues for some time now. It does seem that the "crossconcern" that any swing method call should be made by the EDT, is something that falls into the aspect category. I'm curious if AspectJ can catch swing calls... I could then dump a stack trace.
tbeernotAuthor Commented:
AspectJ (ADTJ) cause my Eclipse 3.1.2 to hang big time. Had to reinstall Eclipse twice (luckily that is easy). So that path was abanoned. I found a class which does a similar check: ThreadCheckingRepaintManager. Hooked in into the application and now it's wait-and-see.
tbeernotAuthor Commented:

It is unbelievable how methods under water can call Swing. It's the do-this, fire event and the listener calls swing execution path. So a "calculateTotal" on a bean may trigger swing. I've got some serious cleaning to do...
tbeernotAuthor Commented:
Currently I'm running with a special swing hook-in to see if the problem still occurs and of course it was vacation time. I'll try and see next week if the problem is gone and if yes accept "Date: 06/19/2006 11:54PM PDT"
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.