Communication problem on double click Tree leaf to trigger download

I added a ItemClickListener to a tree I have which triggers a download action. The file gets downloaded correctly but I get Communication problem displayed on the application.

Here’s my listener:


                 xincoTree.addListener(new ItemClickListener() {

                    @Override
                    public void itemClick(ItemClickEvent event) {
                        if (event.getButton() == ItemClickEvent.BUTTON_LEFT
                                && event.isDoubleClick()
                                && xincoTree.getValue() != null
                                && xincoTree.getValue().toString().startsWith("data")) {
                            downloadFile();
                        }
                    }
                });

And the download action:


               //Download file
                FileDownloadResource downloadResource = new FileDownloadResource(
                        new File(XincoCoreDataServer.getXincoCoreDataPath(XincoDBManager.config.FileRepositoryPath,
                        temp.getId(), temp.getId() + revision)),
                        temp.getXincoAddAttributes().get(0).getAttribVarchar(),
                        Xinco.this);
                getMainWindow().open(downloadResource);
                downloadResource.cleanup();

And the FileDownloadResource class:


package com.bluecubs.xinco.core.server.vaadin;

import com.bluecubs.xinco.core.server.XincoConfigSingletonServer;
import com.vaadin.Application;
import com.vaadin.terminal.DownloadStream;
import com.vaadin.terminal.FileResource;
import java.io.*;
import java.net.URLEncoder;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;

/**
 *
 * @author Javier A. Ortiz Bultrón<javier.ortiz.78@gmail.com>
 */
public class FileDownloadResource extends FileResource {

    private final String fileName;
    private File download;
    private File newFile;

    public FileDownloadResource(File sourceFile, String fileName,
            Application application) {
        super(sourceFile, application);
        this.fileName = fileName;
    }

    protected void cleanup() {
        if (newFile != null && newFile.exists()) {
            newFile.delete();
        }
        if (download != null && download.exists() && download.listFiles().length == 0) {
            download.delete();
        }
    }

    @Override
    public DownloadStream getStream() {
        try {
            //Copy file to directory for downloading
            InputStream in = new CheckedInputStream(new FileInputStream(getSourceFile()),
                    new CRC32());
            download = new File(XincoConfigSingletonServer.getInstance().FileRepositoryPath
                    + System.getProperty("file.separator") + UUID.randomUUID().toString());
            newFile = new File(download.getAbsolutePath() + System.getProperty("file.separator") + fileName);
            download.mkdirs();
            OutputStream out = new FileOutputStream(newFile);
            newFile.deleteOnExit();
            download.deleteOnExit();
            byte[] buf = new byte[1024]
;
            int len;
            while ((len = in.read(buf)) > 0) {
                out.write(buf, 0, len);
            }
            in.close();
            out.close();
            final DownloadStream ds = new DownloadStream(
                    new FileInputStream(newFile), getMIMEType(), fileName);
            ds.setParameter("Content-Disposition", "attachment; filename="
                    + URLEncoder.encode(fileName, "utf-8"));
            ds.setCacheTime(getCacheTime());
            return ds;
        } catch (final FileNotFoundException ex) {
            Logger.getLogger(FileDownloadResource.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } catch (IOException ex) {
            Logger.getLogger(FileDownloadResource.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
}

No error is displayed.

Any idea?
12042.png

Forgot to tell that using the same method, download() from a menu item works fine without the Communication error.

See related
Stackoverflow post
.