-
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?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We should log the stack trace when catching Please add new catch statements for known exceptions (e.g. parse error) and log those without the stack trace. |
||
throw new ExpressionEvaluationException(e.getMessage(), e); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,6 @@ | |
import static org.hamcrest.CoreMatchers.sameInstance; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.params.provider.Arguments.arguments; | ||
|
||
class GenericExpressionEvaluator_ConditionalIT { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. This behavior does not seem correct. |
||
} | ||
|
||
private static Stream<Arguments> validExpressionArguments() { | ||
|
@@ -151,6 +150,7 @@ private static Stream<Arguments> validExpressionArguments() { | |
arguments("/status_code == 200", event("{\"status_code\": 200}"), true), | ||
arguments("/status_code == 200", longEvent, true), | ||
arguments("/status_code != 300", event("{\"status_code\": 200}"), true), | ||
arguments("/status_code >= 300", event("{\"status_code_not_present\": 200}"), false), | ||
arguments("/status_code == 200", event("{}"), false), | ||
arguments("/success == /status_code", event("{\"success\": true, \"status_code\": 200}"), false), | ||
arguments("/success != /status_code", event("{\"success\": true, \"status_code\": 200}"), true), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We should include the cause whenever we catch e.g.
|
||
.log(); | ||
} | ||
} | ||
|
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.
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 think we cover all the cases in the code below. I think we should still consider this an error. If we hit this point we are experiencing indeterminate behavior which is probably best considered as an error state.