Drag and drop

Hello I’m using drag and drop feature in my application.
I cannot remove any component that holds DragAndDropWrapper component in my streamingFinished listener code because it causes vaadin to throw NullPointerException.
See the code

 DropHandler dropHandler = new DropHandler() {
            @Override
            public AcceptCriterion getAcceptCriterion() {
                return AcceptAll.get();
            }

            @Override
            public void drop(DragAndDropEvent event) {
                handleDropEvent(event);
            }
        };


private void handleDropEvent(final DragAndDropEvent dropEvent) {
    DragAndDropWrapper.WrapperTransferable tr = (DragAndDropWrapper.WrapperTransferable)                           dropEvent.getTransferable();
                        Html5File files = tr.getFiles();
   Html5File licFile = files[0]
;
    ....
    StreamVariable licenseFileStreamVariable = new StreamVariable() {
                         ...
                        @Override
                            public void streamingFinished(StreamingEndEvent event) {
                           ...
                          [b]
 //the code that detaches DragAndDropWrapperComponent
                           //(replaces the content of it's parent)  
[/b]
                           }

                           ...
                    };
   licFile.setStreamVariable(licenseFileStreamVariable); 
}

It is because the Vaadin code performs clean-up after executing
streamingFinished
method
FileUploadHandler.cleanStreamVariable(... which in turn uses

owner.getUI() code which causes NullpointerException because owner component is already detached in my
streamisimingFinished
method.

StackTrace:

java.lang.NullPointerException
    at com.vaadin.server.communication.FileUploadHandler$1.run(FileUploadHandler.java:651)
    at com.vaadin.server.VaadinSession.accessSynchronously(VaadinSession.java:1251)
    at com.vaadin.server.communication.FileUploadHandler.cleanStreamVariable(FileUploadHandler.java:648)
    at com.vaadin.server.communication.FileUploadHandler.handleFileUploadValidationAndData(FileUploadHandler.java:435)
    at com.vaadin.server.communication.FileUploadHandler.doHandleXhrFilePost(FileUploadHandler.java:486)
    at com.vaadin.server.communication.FileUploadHandler.handleRequest(FileUploadHandler.java:286)
    at com.vaadin.server.VaadinService.handleRequest(VaadinService.java:1382)
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:238)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

So I’m trying to find a way how to workaround this and don’t see any clear way how to do it (except not removing any component that holds DragAndDropWrapper component in my streamingFinished listener code ofcourse :))


streamingFinished
method looks like correct place to put the code but maybe I’m wrong?
Is this crucial this cleanup code to be executed? What will be if I will continiously omit this problem?

Vaadin experts? Anybody?

Hi Viktor,

I had the same issue and not sure if you came up with a solution. To resolve this, I used
Polling
to update the UI from StreamVariable. I no longer get the NPE.

My code is slightly different from the example and instead referenced the UI methods with UI.getCurrent().

Hope that helps.

I ran into the same issue. submitted a bug report to Vaadin dev team:

http://dev.vaadin.com/ticket/14882

NPE at FileUploadHandler.java:686 when the UI is already disposed