Skip to content

Commit 8649a88

Browse files
Copilotanidotnet
andcommitted
Add null safety checks to set operations in ElementMatchFilter
Co-authored-by: anidotnet <[email protected]>
1 parent 96a991e commit 8649a88

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

nitrite/src/main/java/org/dizitart/no2/filters/ElementMatchFilter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,9 @@ private List<?> applyOrFilterOnIndex(OrFilter orFilter, IndexMap indexMap) {
141141
for (Filter filter : filters) {
142142
if (filter instanceof ComparableFilter) {
143143
List<?> filterResult = ((ComparableFilter) filter).applyOnIndex(indexMap);
144-
resultSet.addAll(filterResult);
144+
if (filterResult != null && !filterResult.isEmpty()) {
145+
resultSet.addAll(filterResult);
146+
}
145147
} else {
146148
// If any filter is not comparable, we can't use index
147149
return new ArrayList<>();
@@ -152,12 +154,16 @@ private List<?> applyOrFilterOnIndex(OrFilter orFilter, IndexMap indexMap) {
152154
}
153155

154156
private List<?> intersect(List<?> list1, List<?> list2) {
157+
if (list1 == null || list1.isEmpty() || list2 == null || list2.isEmpty()) {
158+
return new ArrayList<>();
159+
}
160+
155161
// Convert the second list to a set for O(1) lookup
156162
Set<Object> set2 = new HashSet<>(list2);
157163
List<Object> result = new ArrayList<>();
158164

159165
for (Object item : list1) {
160-
if (set2.contains(item)) {
166+
if (item != null && set2.contains(item)) {
161167
result.add(item);
162168
}
163169
}

0 commit comments

Comments
 (0)