-
Notifications
You must be signed in to change notification settings - Fork 51
fix: equivalent EvaluationContext .equals() not returning true #1756
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Summary of ChangesHello @Vishalup29, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a reported issue where Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR adds consistent equals and hashCode implementations to ImmutableContext and LayeredEvaluationContext, which is a great improvement for SDK users. The logic to base equality on the resolved map from asMap() is correct and aligns with user expectations.
My review focuses on two main areas:
- Performance: The current implementations of
equalsandhashCodecallasMap()on every invocation. This can be inefficient, particularly forLayeredEvaluationContext. I've suggested caching strategies for both classes to mitigate potential performance bottlenecks. - Testing: One of the new tests can be improved to more directly validate the
equalscontract between different context types.
Additionally, I noticed that ImmutableContext still has a Lombok @EqualsAndHashCode annotation. Since you've provided a manual implementation, this annotation is now misleading and should be removed to improve code clarity, though I was unable to comment on that line directly as it was not part of the diff.
src/test/java/dev/openfeature/sdk/LayeredEvaluationContextTest.java
Outdated
Show resolved
Hide resolved
2b7ec29 to
aae0dfa
Compare
|
@Vishalup29 Gemini's comments here are accurate, I think. Lazily building and caching this map is probably a good idea, instead of doing it again with every call... Though I think there's memory trade offs here as well... The comment about the Lombok impl is also right, I think that needs to be removed. cc @chrfwow because I'd like your insights here as well. What do you think? I think either way we'll generate a heap object doing 'asmap' during 'hashcode', so we might as well cache it in case we need it again, right? I think this is optimal as long as we do it lazily? |
|
Yes, we should definetly cache the map when we create it. I have to say I don't really like that the first invocation of |
Yes, I feel exactly the same way. It will be expensive, and allocate memory once, but I think it's still worth having. At least the use case we know of it was just used in test assertions - specifically to validate/assert in a test that a context was set... perhaps this will be the most common use-case. |
aae0dfa to
e712ae9
Compare
|
Thanks for the detailed feedback!
cc: @toddbaert @chrfwow Thanks again for your review. Really appreciate it |
chrfwow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good! I just have some minor comments
src/main/java/dev/openfeature/sdk/LayeredEvaluationContext.java
Outdated
Show resolved
Hide resolved
src/main/java/dev/openfeature/sdk/LayeredEvaluationContext.java
Outdated
Show resolved
Hide resolved
5efa0d5 to
6b7f8dc
Compare
|
@chrfwow Addressed all your comments. |
chrfwow
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
|
thanks, can this be merged? |
…xt and add tests. Signed-off-by: vishalup29 <vishalupadhyay977@gmail.com>
6b7f8dc to
70106a4
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request introduces equals and hashCode implementations for EvaluationContext to provide consistent equality behavior based on resolved attributes, which is a great improvement. The implementations for ImmutableContext and LayeredEvaluationContext are well-structured, with appropriate caching strategies for both immutable and mutable scenarios. The accompanying tests are thorough and cover the new equality semantics effectively. I've identified a few opportunities to enhance performance in the equals and hashCode methods by avoiding unnecessary object allocations, and I've provided specific suggestions in the comments below. Overall, this is a solid contribution that enhances the SDK's functionality.
src/main/java/dev/openfeature/sdk/LayeredEvaluationContext.java
Outdated
Show resolved
Hide resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1756 +/- ##
============================================
+ Coverage 92.53% 93.20% +0.67%
- Complexity 599 604 +5
============================================
Files 55 55
Lines 1406 1427 +21
Branches 154 156 +2
============================================
+ Hits 1301 1330 +29
+ Misses 64 53 -11
- Partials 41 44 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|



Description
This PR adds consistent
equalsandhashCodeimplementations to the SDK’sEvaluationContextimplementations (ImmutableContextandLayeredEvaluationContext).A user reported in Issue #1754 that comparing context instances did not behave as expected,
especially after the introduction of
LayeredEvaluationContext. Because the SDK does notguarantee object identity, equality should be defined based on the resolved attribute map
returned by
asMap().This PR implements that behavior and adds regression tests to ensure we maintain consistent
equality semantics going forward.
Changes
equals(Object)andhashCode()to:ImmutableContextLayeredEvaluationContextasMap()representations.ImmutableContextinstances.LayeredEvaluationContextinstances.ImmutableContextandLayeredEvaluationContext.Related Issue
Fixes #1754
Notes
asMap()rather than structural depth or source layering.