This is an automated email from the ASF dual-hosted git repository.
afs pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/jena.git
The following commit(s) were added to refs/heads/main by this push:
new 2fec11cfde Fixed bug in TDB2's NodeId.compare.
2fec11cfde is described below
commit 2fec11cfde4368009414f5ea46e9929701b75201
Author: Claus Stadler <[email protected]>
AuthorDate: Fri May 22 14:08:23 2026 +0200
Fixed bug in TDB2's NodeId.compare.
---
.../java/org/apache/jena/tdb2/store/NodeId.java | 4 +--
.../org/apache/jena/tdb2/store/TestNodeId.java | 34 ++++++++++++++++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/NodeId.java
b/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/NodeId.java
index 7a75a075bc..589c7f0c1b 100644
--- a/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/NodeId.java
+++ b/jena-tdb2/src/main/java/org/apache/jena/tdb2/store/NodeId.java
@@ -222,8 +222,8 @@ public class NodeId implements Comparable<NodeId>
/** Compare - provides an ordering of {@code NodeIds}. */
public static int compare(NodeId n1, NodeId n2) {
int x = Integer.compare(n1.value1, n2.value1);
- if ( x == 0 )
- return CMP_EQUAL;
+ if ( x != 0 )
+ return x;
return Long.compare(n1.value2, n2.value2);
}
diff --git a/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
b/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
index c1fb36b3f2..32d4aae971 100644
--- a/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
+++ b/jena-tdb2/src/test/java/org/apache/jena/tdb2/store/TestNodeId.java
@@ -23,6 +23,7 @@ package org.apache.jena.tdb2.store;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
@@ -129,4 +130,37 @@ public class TestNodeId
assertEquals(expected, nid1);
}
+ @Test public void nodeId_compare_01() {
+ // Same value - should be equal (0)
+ NodeId n1 = NodeIdFactory.createPtrLong(42, 100L);
+ NodeId n2 = NodeIdFactory.createPtrLong(42, 100L);
+ assertEquals(0, NodeId.compare(n1, n2));
+ assertEquals(0, n1.compareTo(n2));
+ assertTrue(n1.equals(n2));
+ }
+
+ @Test public void nodeId_compare_02() {
+ // Different value1 - value2 should not affect ordering
+ NodeId n1 = NodeIdFactory.createPtrLong(3, 1000L);
+ NodeId n2 = NodeIdFactory.createPtrLong(7, 50L);
+ assertTrue(NodeId.compare(n1, n2) < 0);
+ assertTrue(n1.compareTo(n2) < 0);
+
+ // Reverse direction
+ assertTrue(NodeId.compare(n2, n1) > 0);
+ assertTrue(n2.compareTo(n1) > 0);
+ }
+
+ @Test public void nodeId_compare_03() {
+ // Same value1, different value2 - should compare on value2
+ NodeId n1 = NodeIdFactory.createPtrLong(5, 100L);
+ NodeId n2 = NodeIdFactory.createPtrLong(5, 200L);
+ assertTrue(NodeId.compare(n1, n2) < 0);
+ assertTrue(n1.compareTo(n2) < 0);
+
+ // Reverse direction
+ assertTrue(NodeId.compare(n2, n1) > 0);
+ assertTrue(n2.compareTo(n1) > 0);
+ }
}
+