-
Notifications
You must be signed in to change notification settings - Fork 206
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
Fix null pointer exception during exception evaluation #5217
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
@@ -102,7 +102,6 @@ public Collection<Record<Event>> doExecute(final Collection<Record<Event>> recor | |||
.addArgument(entry.getValueExpression()) | |||
.addArgument(entry.getFormat()) | |||
.addArgument(entry.getValue()) | |||
.setCause(e) |
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.
We should include the cause whenever we catch Exception
. Please add a new catch for the known exception(s) when these errors arise.
e.g.
catch (InvalidExpressionException e) {
// log without exception
} catch (Exception e) {
// log with the exception
}
try { | ||
result = evaluate(statement, context); | ||
if (result == null) { | ||
return false; |
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.
I'm not sure that this is correct. This indicates a bug with our exception handling because any boolean expression should return non-null. Maybe we need to handle this by throwing a more specific exception. Or perhaps we log this case.
@@ -37,7 +37,7 @@ public Object evaluate(ParseTree parseTree, Event event) { | |||
walker.walk(listener, parseTree); | |||
return listener.getResult(); | |||
} catch (final Exception e) { | |||
LOG.error("Unable to evaluate event", e); | |||
LOG.error(e.getMessage()); |
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.
We should log the stack trace when catching Exception
.
Please add new catch statements for known exceptions (e.g. parse error) and log those without the stack trace.
@@ -119,7 +118,7 @@ void testGenericExpressionEvaluatorWithMultipleThreads(final String expression, | |||
void testGenericExpressionEvaluatorThrows(final String expression, final Event event) { | |||
final GenericExpressionEvaluator evaluator = applicationContext.getBean(GenericExpressionEvaluator.class); | |||
|
|||
assertThrows(RuntimeException.class, () -> evaluator.evaluateConditional(expression, event)); | |||
assertThat(evaluator.evaluateConditional(expression, event), equalTo(false)); |
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.
This behavior does not seem correct.
Signed-off-by: Krishna Kondaka <krishkdk@amazon.com>
Description
Fix null pointer exception during exception evaluation.
Modified to check for null objects before evaluating expressions.
Modified to catch exception in conditional expression evaluation and return false instead of throwing the exception
Issues Resolved
Resolves #[Issue number to be closed when this PR is merged]
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.