Issue Details (XML | Word | Printable)

Key: OPENJPA-304
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Kevin Sutter
Reporter: Kevin Sutter
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenJPA

Problems with DepthFirstAnalysis and the IBM JDK

Created: 31/Jul/07 03:33 PM   Updated: 31/Jul/07 07:04 PM
Return to search
Component/s: lib
Affects Version/s: 0.9.7
Fix Version/s: 1.0.0

Time Tracking:
Not Specified

Resolution Date: 31/Jul/07 04:02 PM


 Description  « Hide
TestDepthFirstAnalysis was reporting two errors when running with the IBM JDK. The testcase ran just fine with the Sun JDK. The error conditions were NPE's in testBackEdges and testForwardEdges:

testBackEdges(org.apache.openjpa.lib.graph.TestDepthFirstAnalysis) Time elapsed: 0 sec <<< ERROR!
java.lang.NullPointerException
        at org.apache.openjpa.lib.graph.DepthFirstAnalysis.visit(DepthFirstAnalysis.java:97)
        at org.apache.openjpa.lib.graph.DepthFirstAnalysis.<init>(DepthFirstAnalysis.java:74)
        at org.apache.openjpa.lib.graph.TestDepthFirstAnalysis.setUpGraph2 (TestDepthFirstAnalysis.java:78)
        at org.apache.openjpa.lib.graph.TestDepthFirstAnalysis.testBackEdges(TestDepthFirstAnalysis.java:105)
        :

testForwardEdges(org.apache.openjpa.lib.graph.TestDepthFirstAnalysis) Time elapsed: 0 sec <<< ERROR!
java.lang.NullPointerException
        at org.apache.openjpa.lib.graph.DepthFirstAnalysis.visit(DepthFirstAnalysis.java:97)
        at org.apache.openjpa.lib.graph.DepthFirstAnalysis.<init>(DepthFirstAnalysis.java :74)
        at org.apache.openjpa.lib.graph.TestDepthFirstAnalysis.setUpGraph2(TestDepthFirstAnalysis.java:78)
        at org.apache.openjpa.lib.graph.TestDepthFirstAnalysis.testForwardEdges(TestDepthFirstAnalysis.java :129)
        :

Some debugging with the IBM JDK turned up a couple of problems:

1) The code in DepthFirstAnalysis.java and Edges.java was using == for equality testing instead of .equals(). It turns out that the IBM JDK has an optimization when using Integer instances as keys to HashMaps and new copies of the keys are created (vs using the input key objects directly). Thus, the == check was not sufficient to do the comparison testing.

2) After performing those updates, there was yet another problem with the order of the entries returned by the iterator() of the HashMap. By definition, the
order is not guaranteed with a HashMap implementation. In these particular failing testcases, the Sun JDK was starting with node 2 via the Iterator, while the IBM JDK was starting with node 5. By changing the declaration of this Graph._nodes structure to use a LinkedHashMap (instead of HashMap), we can
reliably determine the order of the iterator. And, now both the Sun and IBM JDK's produce the same results.

Thanks,
Kevin

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Kevin Sutter made changes - 31/Jul/07 04:02 PM
Field Original Value New Value
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Kevin Sutter made changes - 31/Jul/07 07:04 PM
Status Resolved [ 5 ] Closed [ 6 ]