Skip to content

ListDataView throws NPE when no items or data provider have been set before adding a filter #20828

Description

@mshabarov

Description of the bug

When I add filter for in-memory items through ListDataView API for a Grid that doesn't have yet a data provider/items collections, I get an NullPointerException because inMemoryFilter not yet initialised.

Expected behavior

Vaadin Flow shouldn't throw NPE, but instead create an empty data provider lazily, i.e. once any methods of ListDataView is called.

Workaround: call grid.setItems(); before calling data view methods.

Minimal reproducible example

// create a Grid, but not assigning any items
Grid<Person> grid = new Grid<>();

// some TextField that adds a filter upon value change
searchField.addValueChangeListener(event -> {
            if (Objects.nonNull(event.getValue())) {
                this.gridListDataView.addFilter(item -> {
                    final String name = searchField.getValue().trim();
                    if (name.isEmpty()) {
                        return true;
                    }
                    return StringUtils.containsIgnoreCase(item.getName(), name);
                });
            }
        });

Versions

  • Vaadin / Flow version: 24.6.1 and older 24, 23 versions.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status
    🔖 Low Priority (P3)

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions