Intermittent NullPointerException in IndexedTreeNode

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Intermittent NullPointerException in IndexedTreeNode

Mosca, Peter
My current project is nearing its deadline, and I'm getting an intermittent NullPointerException in IndexedTreeNode.getNodeWithinIndex().
 
I'm wondering if anyone else has come across this.  Here is the exception:
 

ca.odell.glazedlists.impl.adt.IndexedTreeNode.getNodeWithIndex(IndexedTreeNode.java:74)

at ca.odell.glazedlists.impl.adt.IndexedTree.getNode(IndexedTree.java:61)

at ca.odell.glazedlists.SortedList.getSourceIndex(SortedList.java:336)

at ca.odell.glazedlists.TransformedList.get(TransformedList.java:116)

at ca.odell.glazedlists.impl.SimpleIterator.next(SimpleIterator.java:53)

at ca.odell.glazedlists.AbstractEventList.toArray(AbstractEventList.java:143)

at java.util.ArrayList.addAll(ArrayList.java:434)

at ca.odell.glazedlists.impl.gui.ThreadProxyEventList.<init>(ThreadProxyEventList.java:69)

at ca.odell.glazedlists.impl.swing.SwingThreadProxyEventList.<init>(SwingThreadProxyEventLis

.java:29)

at ca.odell.glazedlists.swing.GlazedListsSwing.swingThreadProxyList(GlazedListsSwing.java:32

at ca.odell.glazedlists.swing.EventSelectionModel.<init>(EventSelectionModel.java:70)

at com.fgm.tracker.swingclient.searches.ResultsViewModelImpl.getSelectionModel(ResultsViewMo

elImpl.java:326)

at com.fgm.tracker.swingclient.searches.ResultsView.run(ResultsView.java:418)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

 

Looking at the code for the method, it appears that it is possible to reach the offending line without initializing "right" :

    /**
     * Gets the object with the specified index in the tree.
     */
    IndexedTreeNode getNodeWithIndex(int index) {
        // recurse to the left
        if(index < leftSize) {
            return left.getNodeWithIndex(index);

        // recurse on the right side
        } else if(index > leftSize) {
            return right.getNodeWithIndex(index - (leftSize + 1));  <== NullPointerException here

        // return this node's root
        } else {
            return this;
        }
    }

 

Anyone know how I can fix this?

Peter

Reply | Threaded
Open this post in threaded view
|

Re: Intermittent NullPointerException in IndexedTreeNode

Jesse Wilson-2

Hey Peter ---

If you can provide a short test case that demonstrates this problem,
we can probably get it fixed for you within 24 hours. Currently I am
puzzled about how the 'right' property even got to be null, since that
probably means the node is already broken.

Cheers,
Jesse

On 8/30/05, Mosca, Peter <[hidden email]> wrote:
My current project is nearing its deadline, and I'm getting an intermittent NullPointerException in IndexedTreeNode.getNodeWithinIndex().
 
I'm wondering if anyone else has come across this.  Here is the exception:
 

ca.odell.glazedlists.impl.adt.IndexedTreeNode.getNodeWithIndex(IndexedTreeNode.java:74)

at ca.odell.glazedlists.impl.adt.IndexedTree.getNode(IndexedTree.java:61)

at ca.odell.glazedlists.SortedList.getSourceIndex(SortedList.java:336)

at ca.odell.glazedlists.TransformedList.get(TransformedList.java:116)

at ca.odell.glazedlists.impl.SimpleIterator.next(SimpleIterator.java:53)

at ca.odell.glazedlists.AbstractEventList.toArray(AbstractEventList.java:143)

at java.util.ArrayList.addAll(ArrayList.java:434)

at ca.odell.glazedlists.impl.gui.ThreadProxyEventList.<init>(ThreadProxyEventList.java:69)

at ca.odell.glazedlists.impl.swing.SwingThreadProxyEventList.<init>(SwingThreadProxyEventLis

.java:29)

at ca.odell.glazedlists.swing.GlazedListsSwing.swingThreadProxyList(GlazedListsSwing.java:32

at ca.odell.glazedlists.swing.EventSelectionModel.<init>(EventSelectionModel.java:70)

at com.fgm.tracker.swingclient.searches.ResultsViewModelImpl.getSelectionModel(ResultsViewMo

elImpl.java:326)

at com.fgm.tracker.swingclient.searches.ResultsView.run(ResultsView.java:418)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

 

Looking at the code for the method, it appears that it is possible to reach the offending line without initializing "right" :

    /**
     * Gets the object with the specified index in the tree.
     */
    IndexedTreeNode getNodeWithIndex(int index) {
        // recurse to the left
        if(index < leftSize) {
            return left.getNodeWithIndex(index);

        // recurse on the right side
        } else if(index > leftSize) {
            return right.getNodeWithIndex(index - (leftSize + 1));  <== NullPointerException here

        // return this node's root
        } else {
            return this;
        }
    }

 

Anyone know how I can fix this?

Peter


Reply | Threaded
Open this post in threaded view
|

RE: Re: Intermittent NullPointerException in IndexedTreeNode

Mosca, Peter
In reply to this post by Mosca, Peter
Hi Jesse,
 
Thanks a ton for getting back to me on this.  Could this be caused by a malformed Comparator?
 
-Peter


From: Jesse Wilson [mailto:[hidden email]]
Sent: Tuesday, August 30, 2005 8:40 PM
To: [hidden email]
Subject: Re: Intermittent NullPointerException in IndexedTreeNode


Hey Peter ---

If you can provide a short test case that demonstrates this problem,
we can probably get it fixed for you within 24 hours. Currently I am
puzzled about how the 'right' property even got to be null, since that
probably means the node is already broken.

Cheers,
Jesse

On 8/30/05, Mosca, Peter <[hidden email]> wrote:
My current project is nearing its deadline, and I'm getting an intermittent NullPointerException in IndexedTreeNode.getNodeWithinIndex().
 
I'm wondering if anyone else has come across this.  Here is the exception:
 

ca.odell.glazedlists.impl.adt.IndexedTreeNode.getNodeWithIndex(IndexedTreeNode.java:74)

at ca.odell.glazedlists.impl.adt.IndexedTree.getNode(IndexedTree.java:61)

at ca.odell.glazedlists.SortedList.getSourceIndex(SortedList.java:336)

at ca.odell.glazedlists.TransformedList.get(TransformedList.java:116)

at ca.odell.glazedlists.impl.SimpleIterator.next(SimpleIterator.java:53)

at ca.odell.glazedlists.AbstractEventList.toArray(AbstractEventList.java:143)

at java.util.ArrayList.addAll(ArrayList.java:434)

at ca.odell.glazedlists.impl.gui.ThreadProxyEventList.<init>(ThreadProxyEventList.java:69)

at ca.odell.glazedlists.impl.swing.SwingThreadProxyEventList.<init>(SwingThreadProxyEventLis

.java:29)

at ca.odell.glazedlists.swing.GlazedListsSwing.swingThreadProxyList(GlazedListsSwing.java:32

at ca.odell.glazedlists.swing.EventSelectionModel.<init>(EventSelectionModel.java:70)

at com.fgm.tracker.swingclient.searches.ResultsViewModelImpl.getSelectionModel(ResultsViewMo

elImpl.java:326)

at com.fgm.tracker.swingclient.searches.ResultsView.run(ResultsView.java:418)

at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)

at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)

at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)

at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)

at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)

at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

 

Looking at the code for the method, it appears that it is possible to reach the offending line without initializing "right" :

    /**
     * Gets the object with the specified index in the tree.
     */
    IndexedTreeNode getNodeWithIndex(int index) {
        // recurse to the left
        if(index < leftSize) {
            return left.getNodeWithIndex(index);

        // recurse on the right side
        } else if(index > leftSize) {
            return right.getNodeWithIndex(index - (leftSize + 1));  <== NullPointerException here

        // return this node's root
        } else {
            return this;
        }
    }

 

Anyone know how I can fix this?

Peter


Reply | Threaded
Open this post in threaded view
|

Re: Re: Intermittent NullPointerException in IndexedTreeNode

Jesse Wilson-2
Hey Peter --

An inconsistent Comparator can cause
Glazed Lists' SortedList to go into an inconsistent
state, which in turn can reak all sorts of havoc
such as NullPointerExceptions. It's very difficult
to defend against inconsistent Comparators and although
we make some efforts to defend against this, we
can't guarantee that Glazed Lists will work if the
Comparator is inconsistent.

Here's some simple examples that doesn't involve Glazed Lists.

Inconsistent hash codes:
1. Create a class whose hashCode() method returns Random.nextInt();
2. Put elements of that class in a HashSet
3. Test if your HashSet contains the elements you added to it - this will fail,
although probably not with a NullPointerException.

Inconsistent sort order:
1. Create a comparator that always returns 1.
2. Create a TreeSet with that comparator.
3. Add some elements to your TreeSet.
4. Try to clear the TreeSet one element at a time, using this loop:
   while(treeSet.size() > 0) treeSet.remove(treeSet.first());

It turns out that this will create an infinite loop!
So Glazed Lists isn't the lone offender, and Java coders
have to be very careful that they honor the contracts
required by things like Comparator, hashCode(), equals(),
etc. etc.

Cheers,
Jesse