[api][java] Include the memory type in MemoryRef equality and reject null fields - #1153
Merged
Merged
Conversation
sangkyoonnam
force-pushed
the
fix/memory-ref-equality
branch
from
September 23, 2026 19:00
4393a28 to
2699cd4
Compare
Contributor
Author
|
One correction. The description said references with different memory types do not share a hash code, and the test asserted it. |
sangkyoonnam
force-pushed
the
fix/memory-ref-equality
branch
from
September 25, 2026 06:36
81c2e1f to
fd893b7
Compare
…null fields Generated-by: Claude Code 2.1.280 (Claude Fable 5.1)
Generated-by: Claude Code 2.1.280 (Claude Fable 5.1)
sangkyoonnam
force-pushed
the
fix/memory-ref-equality
branch
from
September 28, 2026 04:30
fd893b7 to
5a9c6e9
Compare
wenjin272
approved these changes
Sep 28, 2026
wenjin272
left a comment
Contributor
There was a problem hiding this comment.
Thanks for taking this on. LGTM
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.
Linked issue: #1152
Purpose of change
User-visible outcome
Two
MemoryRefvalues are now equal only when both the memory type and the path are equal;hashCodeandtoStringfollow.MemoryRef.createrejects a null type or path with anIllegalArgumentException. Previously a sensory and a short-term reference to the same path compared equal, hashed together and printed identically, and a null type surfaced later as aNullPointerExceptionfromresolveor from the Jackson serializer.Intent
A reference names a slot in one memory.
equalswas written when the class had only a path (#110); the sensory-memory change added the type without revisiting it. The PythonMemoryRefis a frozen pydantic model and already compares and hashes both fields, so this aligns the Java side with it.Runtime flow
No call path changes.
MemoryObjectImpl#get(MemoryRef)andEventAttachmentUtilsread the type and path through getters and are unaffected. The JSON form already carriesmemory_type, so the existingEventTestround-trip assertion still holds.Key decisions
MemoryObject#get(MemoryRef)resolving by path only, in both languages. Its contract says it "represents the path of the given reference"; whether a reference should be rejected when resolved against the other memory is a separate question.IllegalArgumentExceptionfor a null type or path, matching the class's ownDeserializerand the other recent argument checks inapi.Behavioral Semantics
Interaction decisions
Equality is
type == other.type && path.equals(other.path);hashCodeisObjects.hash(type, path);toStringprints both.createchecks the type first, then the path.Behavioral contracts
toStringnames the memory type and the path.create(null, path)andcreate(type, null)raiseIllegalArgumentException.Failure behavior
The only new failure path is
createwith a null argument, which now throws at construction; nothing is created, logged or absorbed. TheNullPointerExceptiona null type used to cause inresolveand in serialization is no longer reachable.Tests
Contracts to tests
MemoryRefTest.testRefEqualityDistinguishesMemoryTypeMemoryRefTest.testRefEqualityAndHashing(pre-existing)MemoryRefTest.testToStringNamesMemoryTypeMemoryRefTest.testCreateRejectsNullTypeOrPathCoverage and what was not verified
mvn -pl api install && mvn -pl runtime test: 983, 0 failures.mvn -pl api,plan test: 454 and 397, 0 failures.spotless:checkpasses. Without theMemoryRefchange exactly the three new tests fail.The Python side was checked directly against
flink_agents.api.memory_reference: a sensory and a short-term reference to the same path are not equal, a set of both keeps two entries,reprshows the memory type, andcreate(None, path)raisesValidationError. The Python model is unchanged by this PR.Not verified: no production code in
api,planorruntimekeeps references in aSetorMaptoday, so the collection behavior is covered at the unit level only.Implementation invariants and supporting evidence
typeis an enum, so identity comparison is exact.Deserializeralready rejects a missingmemory_typeorpath, socreatenow matches the JSON path.testRefEqualityAndHashingusesSHORT_TERMonly, which is why it did not catch this.API
Compatibility impact
MemoryRefis public API. Only code that relied on two references of different types comparing equal changes behavior; no such use exists in the repository.createnow throws on a null type or path instead of deferring the failure. Python is unchanged.Documentation
doc-neededdoc-not-neededdoc-includedWas this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code 2.1.280 (Claude Fable 5.1)