Important Notice - Forums is archived

To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Product icon

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.

Exceptions from FileDownloader not showing up in ErrorHandler?

Ralf Wagner
8 years ago May 06, 2014 10:45am

I'm currently using Vaadin 7.1.8.

In the UI class for my Vaadin application, I've defined a new ErrorHandler for

UI.getCurrent().setErrorHandler(new MyErrorHandler());

MyErrorHandler implements ErrorHandler and should show all uncaught exceptions, basically with parsing the exception as described in the book of Vaadin 4.5.3 (https://vaadin.com/book/-/page/application.errors.html) and displaying the message from the exception with

new Notification("Error", message, Notification.Type.ERROR_MESSAGE).show(Page.getCurrent());

This usually works fine and displays the error message.

Recently, I've started working with the com.vaadin.server.FileDownloader class. Attaching it to a component (i.e. an image) works fine to start a download. When I tested error situations like using FileDownloader with a FileResource and then removing the file before starting the download, the resulting exception is not shown in my ErrorHandler as it never gets called. Debugging the problem a bit, I found that the DefaultErrorHandler gets called instead.

The API method FileResource.getStream() which is called when the download starts says

Note that this method is called while the session is locked to prevent race conditions but the methods in the returned DownloadStream are assumed to be unrelated to the VaadinSession and are called without holding session locks (to prevent locking the session during long file downloads).

I suppose this to be the cause of the problem, but do not know how to prevent it.
Has anyone encountered the problem before?

Johannes Dahlström
8 years ago May 06, 2014 3:49pm
Ralf Wagner
8 years ago May 07, 2014 7:02am

Hello Johannes,

thanks for the quick reply.

I tried your first proposal with


and my custom ErrorHandler gets called.

Unfortunately, a NullPointerException occurs in

    at com.vaadin.ui.Notification.show(Notification.java:357)

which is called from my code with
    new Notification("Error", message, Notification.Type.ERROR_MESSAGE).show(Page.getCurrent());

and Page.getCurrent() returns null as

    public static Page getCurrent() {
        UI currentUI = UI.getCurrent();
        if (currentUI == null) {
            return null;

UI.getCurrent() returns null. Is this due to the fact, that the FileDownloader is a background task?

>Incidentally, in Vaadin 7.2 this is changed to work in the usual manner so that the connector and its parents in the >hierarchy are recursively searched, making your code work as-is in 7.2 :)

Brilliant, I'll give this a try with Vaadin 7.2. Setting the ErrorHandler just once is much more elegant ;)

Johannes Dahlström
8 years ago May 07, 2014 8:44am
Ralf Wagner
8 years ago May 07, 2014 8:50am