NullPointerException in Grid using navigateTo inside SelectionListener

I try to navigate to a different view and get a NullPointerException inside my Grid.
To reproduce the error I reduce my class to a minimum

import com.vaadin.event.SelectionEvent;
import com.vaadin.event.SelectionEvent.SelectionListener;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
import com.vaadin.ui.Grid;
import com.vaadin.ui.VerticalLayout;

public class GridTest extends VerticalLayout implements View {

    public void enter(ViewChangeEvent event) {
        // Create a grid
        Grid grid = new Grid();

        // Define some columns
        grid.addColumn("name", String.class);
        grid.addColumn("born", Integer.class);

        // Add some data rows
        grid.addRow("Nicolaus Copernicus", 1543);
        grid.addRow("Galileo Galilei", 1564);
        grid.addRow("Johannes Kepler", 1571);

        grid.addSelectionListener(new SelectionListener() {
            public void select(SelectionEvent event) {


By clicking a row I get the following exception

Mai 04, 2015 4:05:20 PM com.vaadin.server.DefaultErrorHandler doDefault Schwerwiegend: java.lang.NullPointerException at com.vaadin.ui.Grid$ at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke( at sun.reflect.DelegatingMethodAccessorImpl.invoke( at java.lang.reflect.Method.invoke( at com.vaadin.server.ServerRpcManager.applyInvocation( at com.vaadin.server.ServerRpcManager.applyInvocation( at com.vaadin.server.communication.ServerRpcHandler.handleInvocations( at com.vaadin.server.communication.ServerRpcHandler.handleRpc( at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest( at com.vaadin.server.SynchronizedRequestHandler.handleRequest( at com.vaadin.server.VaadinService.handleRequest( at com.vaadin.server.VaadinServlet.service( at javax.servlet.http.HttpServlet.service( at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter( at org.apache.catalina.core.ApplicationFilterChain.doFilter( at org.apache.catalina.core.StandardWrapperValve.invoke( at org.apache.catalina.core.StandardContextValve.invoke( at org.apache.catalina.authenticator.AuthenticatorBase.invoke( at org.apache.catalina.core.StandardHostValve.invoke( at org.apache.catalina.valves.ErrorReportValve.invoke( at org.apache.catalina.valves.AccessLogValve.invoke( at org.apache.catalina.core.StandardEngineValve.invoke( at org.apache.catalina.connector.CoyoteAdapter.service( at org.apache.coyote.http11.AbstractHttp11Processor.process( at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process( at$ at java.util.concurrent.ThreadPoolExecutor.runWorker( at java.util.concurrent.ThreadPoolExecutor$ at I get the same exception when using a ItemClickListener instead of a SelectionListener.
Is this a bug or is it not allowed to use navigateTo at this point?


Fascinating. The navigateTo() call immediately detaches the view (and the Grid it contains) from the UI, but processing the selection event relies on the Grid being attached after calling the listeners. More exactly, the RPC handler gets a null from getUI() and fails on this line:

JsonObject diffState = getUI().getConnectorTracker()

The problem probably occurs with any SelectionListener that detaches the Grid from the UI, so it’s not Navigator specific.

That’s a bug! Could you please
file a bug report in Vaadin Trac
? I didn’t notice an existing one about this issue, at least regarding Grid, but it really looks like Grid-specific.

For a workaround, perhaps using a ButtonRenderer (that is, a rendered column with “Show” buttons) would avoid the issue.

I have created a ticket

With the workaround using a ButtonRenderer it works - but in my real project, my container is a LazyQueryContainer and I can’t add a column.



java.lang.IllegalStateException: Container for this Grid is not a default container from Grid() constructor Did you have an idea for this problem?

Hi Oliver,

Grid has basically two modes of operation regarding columns. If a custom data source is not set, Grid uses its own internal container. In this case, the addColumn method adds a column to the Grid and a corresponding property to the internal data source.

On the other hand, if you explicitly set a data source then Grid forbids adding columns that don’t have a matching property in the container. It automatically creates columns based on the container properties, though, so you shouldn’t need to add them manually.