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
Matching inverted exact/regex stream rules when field is not present #2172
Conversation
Before this change, inverted exact/regex rules did not match when the field is not present or null. This is changed and reflected in the tests. Fixes #2160.
return rule.getInverted() ^ value.toString().trim().equals(rule.getValue()); | ||
final String value = msg.getField(rule.getField()).toString(); | ||
|
||
return rule.getInverted() ^ value.trim().equals(rule.getValue()); |
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.
Minor nitpick: While this works, I'd prefer using the logical OR operator here.
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 is not part of the scope of this PR.
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 could do some opportunistic refactoring in this case (and actually fix an error that is accidentally working).
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.
What is the error here?
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.
Using the bitwise OR operator (^
) instead of the logical OR operator (||
) as it's a logical expression to be evaluated and not some bit-shifting.
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 is perfectly fine for booleans, as specified in the JLS: http://docs.oracle.com/javase/specs/jls/se8/html/jls-15.html#jls-15.22.2
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.
Hm, I think I'm getting confused now. The ^
bitwise operator and the ||
logical operator also have different characteristics:
For
^
, the result value istrue
if the operand values are different; otherwise, the result isfalse
.
Is this the intended behavior? The ||
operator would return true
if at least one of the operands is true
while the ^
operator would return true
only if the operands are different (e. g. both are false
). So ^
is like a logical XOR.
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.
Yeah, this is intended. The critical difference is that if the rule is inverted, then it should not match if the message and the rule fields are equal. (field "foo" should not be "bar")
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.
LGTM. 👍 |
Before this change, inverted exact/regex stream rules did not match when the field was not present. This was counter intuitive and perceived as erroneus, this PR Is changing this behavior.
Fixes #2160