[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


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

Posted on 2006-06-19
Medium Priority
Last Modified: 2010-05-18
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(BasicTableUI.java:882)
        at javax.swing.plaf.basic.BasicTableUI$Handler.adjustFocusAndSelection(BasicTableUI.java:942)
        at javax.swing.plaf.basic.BasicTableUI$Handler.mousePressed(BasicTableUI.java:897)
        at java.awt.AWTEventMulticaster.mousePressed(AWTEventMulticaster.java:222)
        at java.awt.Component.processMouseEvent(Component.java:5485)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3126)
        at org.tbee.swing.table.JTableForEdit.processMouseEvent(JTableForEdit.java:244)
        at java.awt.Component.processEvent(Component.java:5253)
        at java.awt.Container.processEvent(Container.java:1966)
        at java.awt.Component.dispatchEventImpl(Component.java:3955)
        at java.awt.Container.dispatchEventImpl(Container.java:2024)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3889)
        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
        at java.awt.Container.dispatchEventImpl(Container.java:2010)
        at java.awt.Window.dispatchEventImpl(Window.java:1774)
        at java.awt.Component.dispatchEvent(Component.java:3803)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
        at org.tbee.swing.StandardComponentPopupMenu.dispatchEvent(StandardComponentPopupMenu.java:98)
        at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
        at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

Now, after unpacking the src.zip in the jdk1.5.0_05 and looking at the BasicTableUI.java 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.

Question by:tbeernot
  • 6
  • 4
LVL 30

Expert Comment

by:Mayank S
ID: 16933307
>> jdk1.5.0_05

I am not sure how stable that is - I would use 1.5.0_06
LVL 92

Expert Comment

ID: 16938404
make sure you aren't making *any* calls in your code that update the gui from a thread other than the event dispatch thread.

Author Comment

ID: 16939977
@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?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 92

Expert Comment

ID: 16940007
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.


Author Comment

ID: 16940077
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.
LVL 92

Expert Comment

ID: 16940117
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.

Author Comment

ID: 16940134
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.
LVL 92

Accepted Solution

objects earned 750 total points
ID: 16940162
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.

Author Comment

ID: 16983226
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.

Author Comment

ID: 17007464

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...

Author Comment

ID: 17230842
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"

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Suggested Courses
Course of the Month19 days, 14 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question