Exception is thrown in client if we put the Grid into dialog and callled "s

I already posted this in the github, but there is no any answer yet, hope someone else could help me.

Exception is thrown in client if we put the Grid into dialog and callled “setDataProvider()” “select” twice

when open the dialog again, fetch the data from DB and set the DataProvider, it should work.

because we often to add some data in some page and go back to another page to open the dialog, that time we should refresh the page content, it should work

Currently It will throw exception in browser

Live Demo
Steps to reproduce

@Route(value = "hello", layout = MainView.class)
@PageTitle("Hello World")
@CssImport("./styles/views/helloworld/hello-world-view.css")
@RouteAlias(value = "", layout = MainView.class)
public class HelloWorldView extends HorizontalLayout {

private Button sayHello;
Dialog dialog = new Dialog();

List<String> list = new ArrayList<>();

private Grid<String> grid = new Grid<String>();

public HelloWorldView() {


    list.add("aa");
    list.add("bb");
    list.add("cc");
    grid.setWidth("300px");
    grid.setHeight("300px");
    grid.addColumn(String::toString);
    dialog.add(grid);

    setId("hello-world-view");
    sayHello = new Button("Say hello");
    add(sayHello);
    sayHello.addClickListener(e -> {
        // we will fetch the data from db in my actual environment, here I just create one list.
        grid.setDataProvider(DataProvider.fromStream(list.stream()));
        Random random = new Random();
        grid.select(list.get(random.nextInt(3)));

        //first time, it will work, everything looks good. But when you call it again ,it will throw exception.
        // this is just one demo, it is different with my actual environment. this code just proves the issue.
        //and it already blocked our development process. hope it could be resolved soon. thanks.
        dialog.open();
    });
}
}

Can you describe what is the exception exactly??

Mayuri Bhuva:
Can you describe what is the exception exactly??

thanks for your reply.
the error is shown as the attachment says.

It is already proved to be a bug. please refer to the following bug in the github.
https://github.com/vaadin/vaadin-grid/issues/1795
18445433.png

I copied your code and run it in my browser. I had the same exception but I solved it by adding a line in your listener before grid.setDataProvider():

grid.getDataProvider().refreshAll();

I hope this helps. Thanks.

Mayuri Bhuva:
I copied your code and run it in my browser. I had the same exception but I solved it by adding a line in your listener before grid.setDataProvider():

grid.getDataProvider().refreshAll();

I hope this helps. Thanks.

WOW! yes, it works if I add “refreshAll()”
currently it is a workaround.
Thanks very much.