Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
mshabarov opened this issue Jan 9, 2025 · 0 comments

Comments

@mshabarov
Copy link
Contributor

mshabarov commented Jan 9, 2025

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.
@mshabarov mshabarov changed the title ListDataView throws NPE when no items or data provider have been set before accessing items ListDataView throws NPE when no items or data provider have been set before adding a filter Jan 9, 2025
@mshabarov mshabarov moved this to 🔖 Normal Priority (P2) in Vaadin Flow bugs & maintenance (Vaadin 10+) Jan 9, 2025
@mshabarov mshabarov moved this from 🔖 Normal Priority (P2) to 🔖 Low Priority (P3) in Vaadin Flow bugs & maintenance (Vaadin 10+) Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🔖 Low Priority (P3)
Development

No branches or pull requests

1 participant