IllegalArgumentException: Null reference passed as parameter when using fileuploadfield

I am evaluating cuba platform / studio . Very good so far… but I came to this error following an example on documentation, Version 6.8

This is the controller code;

package com.company.t1.web.cliente;

import com.haulmont.cuba.gui.components.AbstractEditor;
import com.company.t1.entity.Cliente;

import com.haulmont.cuba.core.entity.FileDescriptor;
import com.haulmont.cuba.core.global.FileStorageException;
import com.haulmont.cuba.gui.components.FileUploadField;
import com.haulmont.cuba.gui.data.DataSupplier;
import com.haulmont.cuba.gui.upload.FileUploadingAPI;

import javax.inject.Inject;
import java.util.Map;

public class ClienteEdit extends AbstractEditor<Cliente> {
@Inject
private FileUploadField ulfimagen;
@Inject
private FileUploadingAPI fileUploadingAPI;
@Inject
private DataSupplier dataSupplier;

@Override
public void init(Map<String, Object> params) {
   ulfimagen.addFileUploadSucceedListener(event -> {
        FileDescriptor fd = ulfimagen.getFileDescriptor();
        try {
            // save file to FileStorage
       //     FileDescriptor userImageFile = Cliente.getImagen();
       //     imgimagen.setSource(FileDescriptorResource.class).setFileDescriptor(userImageFile);
            fileUploadingAPI.putFileIntoStorage(ulfimagen.getFileId(), fd);
        } catch (FileStorageException e) {
            throw new RuntimeException("Error saving file to FileStorage", e);
        }
        // save file descriptor to database
        dataSupplier.commit(fd);
        showNotification("Uploaded file: " + ulfimagen.getFileName(), NotificationType.HUMANIZED);
    });

    ulfimagen.addFileUploadErrorListener(event ->
            showNotification("File upload error", NotificationType.HUMANIZED));
}
}

This is the layout

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<window xmlns="http://schemas.haulmont.com/cuba/window.xsd"
        caption="msg://editorCaption"
        class="com.company.t1.web.cliente.ClienteEdit"
        datasource="clienteDs"
        focusComponent="tfPrimerNombre"
        messagesPack="com.company.t1.web.cliente">
    <dsContext>
        <datasource id="clienteDs"
                    class="com.company.t1.entity.Cliente"
                    view="cliente-view_1"/>
    </dsContext>
    <dialogMode height="600"
                width="800"/>
    <layout expand="windowActions"
            spacing="true">
        <grid caption="Datos del Cliente"
              responsive="true"
              spacing="true"
              width="800px">
            <columns count="4"/>
            <rows>
                <row>
                    <label id="lbPrimerNombre"
                           align="MIDDLE_LEFT"
                           height="20px"
                           value="Primer Nombre"/>
                    <textField id="tfPrimerNombre"
                               align="MIDDLE_LEFT"
                               datasource="clienteDs"
                               property="primerNombre"
                               width="150px"/>
                    <label id="lbSegundoNombre"
                           align="MIDDLE_LEFT"
                           responsive="true"
                           value="Segundo Nombre"/>
                    <textField id="tfSegundoNombre"
                               datasource="clienteDs"
                               property="segundoNombre"/>
                </row>
                <row>
                    <label align="MIDDLE_LEFT"
                           value="Primer Apellido"/>
                    <textField id="tfPrimer Apellido"
                               datasource="clienteDs"
                               height="32px"
                               property="primerApellido"
                               width="150px"/>
                    <label id="lbSegundoApellido"
                           align="MIDDLE_LEFT"
                           height="17px"
                           responsive="true"
                           value="Segundo Apellido"/>
                    <textField id="tfSegundoApellido"
                               datasource="clienteDs"
                               property="segundoApellido"/>
                </row>
                <row>
                    <dateField id="dfFechaNacimiento"
                               caption="Fecha de Nacimiento"
                               datasource="clienteDs"
                               height="31px"
                               property="fechaNacimiento"/>
                    <lookupField id="lfPaisNacimiento"
                                 caption="Pais de Nacimiento"
                                 datasource="clienteDs"
                                 optionsEnum="com.company.t1.entity.Pais"
                                 property="paisNacimiento"/>
                    <textField id="tfNacionalidad"
                               caption="Nacionalidad"
                               datasource="clienteDs"
                               height="30px"
                               property="nacionalidad"/>
                    <lookupField id="lfgenero"
                                 caption="Genero"
                                 datasource="clienteDs"
                                 optionsEnum="com.company.t1.entity.Genero"
                                 property="genero"
                                 required="true"
                                 responsive="true"/>
                </row>
                <row>
                    <lookupField id="lfTipoIdentificacion"
                                 caption="Tipo de Identificacion"
                                 colspan="3"
                                 datasource="clienteDs"
                                 height="34px"
                                 optionsEnum="com.company.t1.entity.TipoIdentificacion"
                                 property="tipoIdent"/>
                    <textField id="tfIdentificacion"
                               caption="Numero de Identificacion"
                               datasource="clienteDs"
                               height="31px"
                               property="identificacacion"/>
                </row>
                <row>
                    <upload id="ulfimagen"
                            datasource="clienteDs"
                            fileStoragePutMode="IMMEDIATE"
                            property="imagen"/>
                </row>
                <row/>
            </rows>
        </grid>
        <hbox height="44px"
              margin="true"
              responsive="true"
              spacing="true"/>
        <frame id="windowActions"
               screen="editWindowActions"/>
    </layout>
</window>
java.lang.IllegalArgumentException: Null reference passed as parameter
	at com.haulmont.bali.util.Preconditions.checkNotNullArgument(Preconditions.java:39)
	at com.haulmont.cuba.gui.upload.FileUploading.uploadFileIntoStorage(FileUploading.java:246)
	at com.haulmont.cuba.gui.upload.FileUploading.putFileIntoStorage(FileUploading.java:233)
	at com.company.t1.web.cliente.ClienteEdit.lambda$init$0(ClienteEdit.java:37)
	at com.haulmont.bali.events.EventRouter.fireEvent(EventRouter.java:45)
	at com.haulmont.cuba.web.gui.components.WebFileUploadField.fireFileUploadSucceed(WebFileUploadField.java:470)
	at com.haulmont.cuba.web.gui.components.WebFileUploadField.lambda$initUploadButton$982e378a$1(WebFileUploadField.java:278)
	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:498)
	at com.vaadin.event.ListenerMethod.receiveEvent(ListenerMethod.java:510)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:200)
	at com.vaadin.event.EventRouter.fireEvent(EventRouter.java:163)
	at com.vaadin.server.AbstractClientConnector.fireEvent(AbstractClientConnector.java:1037)
	at com.haulmont.cuba.web.toolkit.ui.CubaFileUpload.fireUploadSuccess(CubaFileUpload.java:484)
	at com.haulmont.cuba.web.toolkit.ui.CubaFileUpload$1.fileUploaded(CubaFileUpload.java:72)
	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:498)
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:158)
	at com.vaadin.server.ServerRpcManager.applyInvocation(ServerRpcManager.java:119)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocation(ServerRpcHandler.java:444)
	at com.vaadin.server.communication.ServerRpcHandler.handleInvocations(ServerRpcHandler.java:409)
	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:1435)
	at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:361)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.serviceAppRequest(CubaApplicationServlet.java:300)
	at com.haulmont.cuba.web.sys.CubaApplicationServlet.service(CubaApplicationServlet.java:191)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CompositeFilter$VirtualFilterChain.doFilter(CompositeFilter.java:107)
	at org.springframework.web.filter.CompositeFilter.doFilter(CompositeFilter.java:73)
	at com.haulmont.cuba.web.sys.CubaHttpFilter.doFilter(CubaHttpFilter.java:107)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

Hi,

There is no need to perform custom file saving, since you are using IMMEDIATE mode of FileUploadField. File will be saved and set to the entity automatically. That’s why ulfimagen.getFileId() is null, temporary file already saved and removed from temp storage.

So, you can simply remove your ulfimagen.addFileUploadSucceedListener code.

Thanks Yuriy. You have been of great help. Problem solved.
Your comments confirm what I thought, It was like it was doing the save twice.