Repository navigation
fix: preserve Instant precision when cloning a Value - #2071
Open
RaphaelFakhri wants to merge 1 commit into
Open
RaphaelFakhri wants to merge 1 commit into
RaphaelFakhri wants to merge 1 commit into
Conversation
Value.clone() rebuilt Instant values with Instant.ofEpochMilli, which drops sub-millisecond precision. ImmutableStructure and ImmutableContext clone values on construction and on every read, so getValue() returned a different instant than the one stored. Instant is immutable, so the original instance is reused instead. Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
|
chrfwow
approved these changes
Nov 9, 2026
This branch has not been deployed
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.



This PR
Value.clone()copiedInstantvalues withInstant.ofEpochMilli(...), which drops sub-millisecond precision.ImmutableStructure(and soImmutableContext) clones values on construction and on every read, sogetValue(key).asInstant()returned a different instant than the one stored.Instantis immutable, soclone()now reuses the original instance.ImmutableStructureTest.getValueShouldPreserveInstantPrecision, which checksgetValue,asMapandasObjectMapwith a nanosecond-precision instant.Related Issues
Fixes #2070
Notes
The existing
MutatingGetInstantValueShouldNotChangeOriginalValuetest truncatesInstant.now()to milliseconds to avoid this behavior. It still passes and is left unchanged.How to test
./mvnw test -Dtest=ImmutableStructureTestWithout the change in
Value.java, the new test fails withexpected: <2023-11-14T22:13:20.123456789Z> but was: <2023-11-14T22:13:20.123Z>.