-
Notifications
You must be signed in to change notification settings - Fork 52
fix: Fix StackOverflow on recursive contexts #1760
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
Summary of ChangesHello @chrfwow, 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 resolves a critical 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 pull request addresses a potential StackOverflowError that can occur in LayeredEvaluationContext when a before hook returns its input context, creating a recursive reference. The fix in HookSupport.java correctly prevents this by adding a reference equality check. A new test case has been added to HookSupportTest.java to verify this fix. My review includes a suggestion to improve the assertion in the new test to make it more explicit and idiomatic.
| layeredEvaluationContext.asObjectMap(); | ||
|
|
||
| assertThatNoException(); |
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.
The use of assertThatNoException() here is not idiomatic. It creates an assertion object that is not used, and the test relies on an uncaught exception to fail. A more explicit and robust way to assert that no exception is thrown is to use isThrownBy() with a lambda or method reference. This clearly states which part of the code is expected not to throw an exception.
| layeredEvaluationContext.asObjectMap(); | |
| assertThatNoException(); | |
| assertThatNoException().isThrownBy(layeredEvaluationContext::asObjectMap); |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1760 +/- ##
============================================
+ Coverage 92.46% 93.66% +1.20%
- Complexity 597 602 +5
============================================
Files 55 55
Lines 1406 1406
Branches 154 154
============================================
+ Hits 1300 1317 +17
+ Misses 64 50 -14
+ Partials 42 39 -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:
|
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>
| var returnedContext = returnedEvalContext.get(); | ||
| if (!returnedContext.isEmpty()) { | ||
| // yes, we want to check for reference equality here, this prevents recursive layered contexts | ||
| if (returnedContext != hookContext.getCtx() && !returnedContext.isEmpty()) { |
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.
| if (returnedContext != hookContext.getCtx() && !returnedContext.isEmpty()) { | |
| if (!returnedContext.isEmpty() && returnedContext != hookContext.getCtx()) { |
[Q] would java optimize this anyway or could this be a slight improvement checking for empty first?
|
Signed-off-by: christian.lutnik <christian.lutnik@dynatrace.com>



This PR
The new
LayeredEvaluationContextcan result in aStackOverflowExceptionwhen a before hook returns the passed hook context. This would result in theLayeredEvaluationContexthaving a reference to itself in the hook context layer. As soon astoMap,toObjectMapor similar is called, an exception will be thrown.