NIFI-6127: Fixed NPE in match() and find() EL functions when attribute doesn't exist

This closes #3378.

Signed-off-by: Koji Kawamura <ijokarumawak@apache.org>
This commit is contained in:
Matthew Burgess 2019-03-19 14:03:57 -04:00 committed by Koji Kawamura
parent 0cb15cfb1a
commit 06f41ac6f8
3 changed files with 16 additions and 2 deletions

View File

@ -53,7 +53,11 @@ public class FindEvaluator extends BooleanEvaluator {
} }
final Pattern pattern; final Pattern pattern;
if (compiledPattern == null) { if (compiledPattern == null) {
pattern = Pattern.compile(search.evaluate(attributes).getValue()); String expression = search.evaluate(attributes).getValue();
if (expression == null) {
return new BooleanQueryResult(false);
}
pattern = Pattern.compile(expression);
} else { } else {
pattern = compiledPattern; pattern = compiledPattern;
} }

View File

@ -53,7 +53,11 @@ public class MatchesEvaluator extends BooleanEvaluator {
} }
final Pattern pattern; final Pattern pattern;
if (compiledPattern == null) { if (compiledPattern == null) {
pattern = Pattern.compile(search.evaluate(attributes).getValue()); String expression = search.evaluate(attributes).getValue();
if (expression == null) {
return new BooleanQueryResult(false);
}
pattern = Pattern.compile(expression);
} else { } else {
pattern = compiledPattern; pattern = compiledPattern;
} }

View File

@ -1324,6 +1324,9 @@ public class TestQuery {
assertEquals("false", secondEvaluation); assertEquals("false", secondEvaluation);
verifyEquals("${dotted:matches('abc\\.xyz')}", attributes, true); verifyEquals("${dotted:matches('abc\\.xyz')}", attributes, true);
// Test for matches(null)
assertEquals("false", Query.evaluateExpressions("${abc:matches(${not.here})}", attributes, null));
} }
@Test @Test
@ -1344,6 +1347,9 @@ public class TestQuery {
assertEquals("false", secondEvaluation); assertEquals("false", secondEvaluation);
verifyEquals("${dotted:find('\\.')}", attributes, true); verifyEquals("${dotted:find('\\.')}", attributes, true);
// Test for find(null)
assertEquals("false", Query.evaluateExpressions("${abc:find(${not.here})}", attributes, null));
} }
@Test @Test