Skip to content

Commit

Permalink
Merge pull request #4537 from gchq/gh-4534_NPE
Browse files Browse the repository at this point in the history
#4534 Fix NPE in include/exclude filter
  • Loading branch information
stroomdev66 authored Oct 14, 2024
2 parents b97e058 + 480caba commit 1f86f94
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@
import java.util.function.Predicate;
import java.util.regex.Pattern;

public class CompiledIncludeExcludeFilter implements Predicate<String> {

private final Filter filter;
private final Predicate<String> predicate;

private CompiledIncludeExcludeFilter(final Filter filter,
final Predicate<String> predicate) {
this.filter = filter;
this.predicate = predicate;
}
public class CompiledIncludeExcludeFilter {

public static Optional<Predicate<String>> create(final Filter filter, final Map<String, String> paramMap) {
if (filter == null) {
Expand Down Expand Up @@ -73,14 +64,6 @@ public static Optional<Predicate<String>> create(final Filter filter, final Map<
return optional;
}

@Override
public boolean test(final String value) {
final String v = value == null
? ""
: value;
return predicate.test(v);
}

private static List<Pattern> createPatternList(final String patterns, final Map<String, String> paramMap) {
List<Pattern> patternList = null;
if (patterns != null && !patterns.trim().isEmpty()) {
Expand All @@ -97,9 +80,4 @@ private static List<Pattern> createPatternList(final String patterns, final Map<

return patternList;
}

@Override
public String toString() {
return filter.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import stroom.query.language.functions.Val;
import stroom.query.language.functions.ref.StoredValues;
import stroom.query.language.functions.ref.ValueReferenceIndex;
import stroom.util.NullSafe;

import com.google.common.base.Predicates;

Expand Down Expand Up @@ -100,12 +101,15 @@ public static Predicate<Val[]> create(final ExpressionOperator rowExpression,
for (final UsedColumn usedColumn : usedColumns) {
final Generator generator = usedColumn.generator;
generator.set(values, storedValues);
final String value = generator.eval(storedValues, null).toString();
final Val val = generator.eval(storedValues, null);
final String text = NullSafe.getOrElse(val, Val::toString, "");
// As soon as we fail a predicate test for a column then return false.
if (!usedColumn.columnIncludeExcludePredicate.test(value)) {
if (!usedColumn.columnIncludeExcludePredicate.test(text)) {
return false;
}
usedColumn.mapConsumer.accept(columnNameToValueMap, value);
// TODO : Provide a map of Val to the row predicate as opposed to strings.
// Fix the row expression matcher to deal with Vals.
usedColumn.mapConsumer.accept(columnNameToValueMap, val.toString());
}

// Test the row value map.
Expand Down
24 changes: 24 additions & 0 deletions unreleased_changes/20241014_145542_566__4534.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
* Issue **#4534** : Fix NPE in include/exclude filter.


```sh
# ********************************************************************************
# Issue title: Empty Query Term gives FATAL in Alert popup
# Issue link: https://github.com/gchq/stroom/issues/4534
# ********************************************************************************

# ONLY the top line will be included as a change entry in the CHANGELOG.
# The entry should be in GitHub flavour markdown and should be written on a SINGLE
# line with no hard breaks. You can have multiple change files for a single GitHub issue.
# The entry should be written in the imperative mood, i.e. 'Fix nasty bug' rather than
# 'Fixed nasty bug'.
#
# Examples of acceptable entries are:
#
#
# * Issue **123** : Fix bug with an associated GitHub issue in this repository
#
# * Issue **namespace/other-repo#456** : Fix bug with an associated GitHub issue in another repository
#
# * Fix bug with no associated GitHub issue.
```

0 comments on commit 1f86f94

Please sign in to comment.