NPE with Integer bound to grid when cell set to blank.

I’m using vaading 8.0.6 building a grid that has an integer bound to a text field in a grid via;

   TextField length = new TextField();
    
        Binding<RequiredPart, Integer> bindLength = binder.forField(length)
                .withNullRepresentation("")
                .withConverter(new StringToIntegerConverter("Must enter a number"))
                .bind(RequiredPart::getLength, RequiredPart::setLength);
        grid.addColumn(RequiredPart::getLength).setCaption("Length").setEditorBinding(bindLength).setWidth(150);

RequiredPart is a pojo and the length getters/setters are:

  public int getLength()
    {
        return length;
    }

    public void setLength(int length)
    {
        this.length = length;
    }

The grid is in non-buffered mode:

        grid = new Grid<RequiredPart>();
        grid.getEditor().setBuffered(false);
        grid.setSizeFull();
        layout.addComponent(grid);

To get the detailed NPE all I need to do is double click a cell in the length colum, clear the field out hit enter.

If I debug the NPE it has a suppressed exception of :

Collections$UnmodifiableRandomAccessList<E> The full stack trace is:

SEVERE: 
java.lang.NullPointerException
    at com.vaadin.data.Binder$BindingImpl.lambda$writeFieldValue$22abd369$1(Binder.java:948)
    at com.vaadin.data.SimpleResult.handle(SimpleResult.java:78)
    at com.vaadin.data.Result.ifOk(Result.java:146)
    at com.vaadin.data.Binder$BindingImpl.writeFieldValue(Binder.java:948)
    at com.vaadin.data.Binder$BindingImpl.handleFieldValueChange(Binder.java:915)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:211)
    at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:174)
    at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1029)
    at com.vaadin.ui.AbstractField.setValue(AbstractField.java:144)
    at com.vaadin.ui.AbstractTextField$AbstractTextFieldServerRpcImpl.setText(AbstractTextField.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:155)
    at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:116)
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:445)
    at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:410)
    at com.vaadin.server.communication.ServerRpcHandler.handleRpc(ServerRpcHandler.java:274)
    at com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(UidlRequestHandler.java:90)
    at com.vaadin.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:41)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1464)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:381)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

Hi Brett,

In Java primitive types and
null
s do not mix very well. You should use
Integer
instead of
int
if you want to be able to handle
null
s properly. Passing a
null
to a setter that waits for
int
is always NPE.

//Teemu

thanks for the response.
I wonder if the api should make this a litte more obvious. Maybe a precondition.