perf: skip unmodifiableMap wrapper when hookHints is empty#1953
perf: skip unmodifiableMap wrapper when hookHints is empty#1953tobias-ibounig-dt wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes the initialization of hookSupportData.hints in OpenFeatureClient.java by using Collections.emptyMap() when the hook hints are empty. A review comment points out that getHookHints() could return null, which would cause a NullPointerException when calling isEmpty(), and suggests adding a null check to handle this case safely.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| var hookHints = flagOptions.getHookHints(); | ||
| hookSupportData.hints = hookHints.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(hookHints); |
There was a problem hiding this comment.
If flagOptions.getHookHints() returns null (which can happen if hookHints is explicitly set to null via the builder in FlagEvaluationOptions), calling hookHints.isEmpty() will throw a NullPointerException.
To ensure robust defensive programming, we should handle the null case gracefully by defaulting to Collections.emptyMap().
| var hookHints = flagOptions.getHookHints(); | |
| hookSupportData.hints = hookHints.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(hookHints); | |
| var hookHints = flagOptions.getHookHints(); | |
| hookSupportData.hints = hookHints == null || hookHints.isEmpty() ? Collections.emptyMap() : Collections.unmodifiableMap(hookHints); |
There was a problem hiding this comment.
I think this is something that should be handled in the builder, but idk if we can modify this, since I assume it will be a lombok builder. Can we add a test to make sure we won't have a NPE?
There was a problem hiding this comment.
ensured in builder that it can't be null
Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
3e4b703 to
d583cd2
Compare
|
Same codecov-action issue as #1955 (comment) - rebasing this PR onto main should fix it. cc @chrfwow |
Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
|
Realized another thing in |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1953 +/- ##
============================================
+ Coverage 92.27% 93.28% +1.01%
- Complexity 653 658 +5
============================================
Files 59 59
Lines 1592 1594 +2
Branches 179 181 +2
============================================
+ Hits 1469 1487 +18
+ Misses 76 62 -14
+ Partials 47 45 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Signed-off-by: Tobias Ibounig <tobias.ibounig@dynatrace.com>
|
The current build issue can be fixed by running spotless:apply |
Oh sorry, I thought I made sure to run it every time. |
|



This PR
Collections.unmodifiableMap()wrapper whenhookHintsis empty (the common case)Related Issues
None
Notes
hookHintsis resolved once per flag evaluation. Previously it was always wrapped in an unmodifiable view, even when empty. This PR avoids that allocation by returningCollections.emptyMap()directly when there areno hints.
Allocation impact is negligible, but reduces on
totalAllocatedInstancescan be seen.main(baseline)run:+totalAllocatedBytesrun:+totalAllocatedInstancesFollow-up Tasks