I’d suggest you to try calling this.gridListDataView.addFilter() in the searchField component listener instead and only call addItem in the subscribe callbacks.
The NPE reason here is probably that addFilter calls refreshAll internally and some items are null at that point or pin is null.
java.lang.NullPointerException: Cannot invoke "com.vaadin.flow.function.SerializableConsumer.accept(Object)" because "inMemoryFilter" is null
at com.vaadin.flow.component.grid.Grid.updateInMemoryFiltering(Grid.java:5072) ~[vaadin-grid-flow-24.5.8.jar:na]
at com.vaadin.flow.component.grid.Grid.onInMemoryFilterOrSortingChange(Grid.java:5058) ~[vaadin-grid-flow-24.5.8.jar:na]
at com.vaadin.flow.data.provider.AbstractListDataView.fireFilteringOrSortingChangeEvent(AbstractListDataView.java:405) ~[flow-data-24.5.9.jar:24.5.9]
searchField.addValueChangeListener(event -> {
if (Objects.nonNull(event.getValue())) {
Animated.animate(grid, Animated.Animation.FADE_IN);
this.gridListDataView.addFilter(item -> {
final String name = searchField.getValue().trim();
if (name.isEmpty()) {
return true;
}
return StringUtils.containsIgnoreCase(item.getPin().getPin(), name);
});
spanRelaysCount.setText(String.valueOf(this.gridListDataView.getItems().count()).concat(" Total"));
spanRelaysCount.setVisible(true);
}
});
Now I see, thanks.
A possible reason for having inMemoryFilter null is that you never call grid.setItems or grid.setDataProvider before you call addFilter.
Could you please try to call grid.setItems(); before adding a value change listener? This should add an empty list of items to grid and should prevent grid to throw NPE.
This is by the way good use case. I believe Flow can create an empty items list and data provider if it’s not defined at the time you call getListDataView().anyMethod().