Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

kkondaka
Copy link
Collaborator

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

  • [ X] New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • [X ] Commits are signed with a real name per the DCO

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.

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)
Copy link
Member

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;
Copy link
Member

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());
Copy link
Member

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));
Copy link
Member

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants