Solved

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

Posted on 2006-06-19
12
1,040 Views
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:

java.lang.NullPointerException
        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) {
            table.getSelectionModel().setValueIsAdjusting(flag);
            table.getColumnModel().getSelectionModel().
                    setValueIsAdjusting(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):

org.tbee.swing.StandardComponentPopupMenu.dispatchEvent

and

org.tbee.swing.table.JTableForEdit.processMouseEvent

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):

Toolkit.getDefaultToolkit().getSystemEventQueue().push(getStandardComponentPopupMenu());

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
            super.processMouseEvent(e);
      }

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.

0
Comment
Question by:tbeernot
  • 6
  • 4
12 Comments
 
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
0
 
LVL 92

Expert Comment

by:objects
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.
0
 
LVL 2

Author Comment

by:tbeernot
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?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 92

Expert Comment

by:objects
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.

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
0
 
LVL 2

Author Comment

by:tbeernot
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.
0
 
LVL 92

Expert Comment

by:objects
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.
0
 
LVL 2

Author Comment

by:tbeernot
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.
0
 
LVL 92

Accepted Solution

by:
objects earned 250 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.
0
 
LVL 2

Author Comment

by:tbeernot
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.
0
 
LVL 2

Author Comment

by:tbeernot
ID: 17007464
Autch.

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...
0
 
LVL 2

Author Comment

by:tbeernot
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"
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java.io.BufferedReader   readLine()  //returns the entire file ? 4 73
egit plugin on eclipse 8 64
maven module vs maven project 3 23
String array comparison 4 34
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 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