Repository navigation
Declare equals/hashCode consistent with compareTo (CodeQL java/inconsistent-compareto-and-equals) - #232
Merged
vharseko merged 2 commits intoJul 16, 2026
Conversation
…istent-compareto-and-equals) Three persistit engine classes implemented Comparable/compareTo but inherited Object.equals, so equals and compareTo could disagree: - BufferPool.BufferHolder (sorted via Arrays.sort by volumeId, page) - JournalManager.TransactionMapItem (held in a TreeSet, ordered by timestamp) - TreeBuilder.Node (keyed in a TreeMap, ordered by tree + key) None of these types is currently compared through equals/hashCode - the sorted collections (TreeMap, TreeSet, Arrays.sort) all use compareTo, and the types are never placed in a hash collection keyed by themselves nor looked up via contains/indexOf/remove(Object). The inconsistency was therefore latent, but CodeQL flags it and it is a real trap for future callers. Add equals and hashCode to each class, defined so that two instances are equal exactly when compareTo returns 0, and hashCode is derived from the same ordering key. Because nothing relied on the inherited identity equals, this is behaviour-preserving for all existing usages. Also add the missing 3A Systems Portions header line to JournalManager.java (TreeBuilder.java and BufferPool.java already carry it).
maximthomas
approved these changes
Jul 8, 2026
vharseko
added a commit
that referenced
this pull request
Jul 17, 2026
* Drop the stale animal-sniffer Java 1.7 API check from persistit The persistit modules pinned animal-sniffer to the signature org.codehaus.mojo.signature:java17:1.0 — the Java 1.7 API surface — inherited from the upstream Akiban Persistit build. The project compiles at maven.compiler.release=11, so the check enforced a baseline three releases below the declared one, and javac already enforces the real baseline natively via `release`. The check was redundant and wrong. It never ran in CI until #270 switched the build from `mvn package` to `mvn verify`: animal-sniffer binds to the verify phase. Once it started running it failed on Java 8 APIs merged earlier under `mvn package` — ThreadLocal.withInitial (#228) and Long.hashCode(long) (#232). Remove the plugin declarations from the core and ui modules along with the signature properties in the parent. Nothing else refers to it: there are no @IgnoreJRERequirement annotations in the tree. * Add the missing license headers to the persistit poms The three persistit poms carried no license header. They are not upstream Akiban files: they were added in #12 when the build artifacts were reorganized, so there is no upstream owner to preserve. Use the CDDL block of the root pom, which is their parent, with a standalone 3A Systems copyright covering 2020 (when the files were added) through the current year.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves all three open
java/inconsistent-compareto-and-equalsCodeQL alertsin the persistit engine. Each flagged class implements
Comparable/compareTobut inherited
Object.equals, soequalsandcompareTocould beinconsistent:
compareToorders byBufferPool.BufferHoldervolumeId,pageArrays.sortJournalManager.TransactionMapItemTreeSet, sortedListTreeBuilder.NodekeyTreeMap<Node, Node>Why it is safe
None of these types is currently compared through
equals/hashCode:TreeMap,TreeSet,Arrays.sort,Collections.sort) all usecompareTo, notequals;(
TransactionMapItemis only a value in aHashMap<Long, …>), andcontains/indexOf/remove(Object)call that would invokeequalson them.So the inconsistency was latent rather than an active bug, but it is exactly
the trap this rule guards against for future callers.
Fix
For each class, declare
equalsandhashCodeconsistent with the existingcompareTo:equals(o)returns true iffois the same reference orcompareTo(o) == 0;hashCodeis derived from the same ordering key(
(volumeId, page); commit-or-start timestamp; the tree instance for aNode).Because nothing relied on the inherited identity
equals, behaviour isunchanged for every existing usage.
Also adds the missing
Portions Copyrighted 2026 3A Systems, LLCheader lineto
JournalManager.java(TreeBuilder.javaandBufferPool.javaalreadycarry it).
Testing
mvn -o -pl persistit/core -am compile— BUILD SUCCESS.