From 02c8f54ea97f812bac899e565a98f29a83bf2977 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 19 Feb 2010 09:46:18 +0000 Subject: [PATCH] Fix for #3860 - FileResource.getStream should not consume FileNotFoundException svn changeset:11395/svn branch:6.3 --- src/com/vaadin/terminal/FileResource.java | 12 ++++- .../resources/NonExistingFileResource.java | 48 +++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/src/com/vaadin/tests/resources/NonExistingFileResource.java diff --git a/src/com/vaadin/terminal/FileResource.java b/src/com/vaadin/terminal/FileResource.java index 46f1a6c028..7a9feae674 100644 --- a/src/com/vaadin/terminal/FileResource.java +++ b/src/com/vaadin/terminal/FileResource.java @@ -10,6 +10,7 @@ import java.io.FileNotFoundException; import com.vaadin.Application; import com.vaadin.service.FileTypeResolver; +import com.vaadin.terminal.Terminal.ErrorEvent; /** * FileResources are files or directories on local filesystem. The @@ -67,7 +68,16 @@ public class FileResource implements ApplicationResource { ds.setCacheTime(cacheTime); return ds; } catch (final FileNotFoundException e) { - // No logging for non-existing files at this level. + // Log the exception using the application error handler + getApplication().getErrorHandler().terminalError(new ErrorEvent() { + + @Override + public Throwable getThrowable() { + return e; + } + + }); + return null; } } diff --git a/tests/src/com/vaadin/tests/resources/NonExistingFileResource.java b/tests/src/com/vaadin/tests/resources/NonExistingFileResource.java new file mode 100644 index 0000000000..b894756603 --- /dev/null +++ b/tests/src/com/vaadin/tests/resources/NonExistingFileResource.java @@ -0,0 +1,48 @@ +package com.vaadin.tests.resources; +import java.io.File; + +import com.vaadin.terminal.FileResource; +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; + +public class NonExistingFileResource extends TestBase { + + @Override + protected void setup() { + Button existing = createButton("WEB-INF/web.xml"); + Button nonExisting = createButton("WEB-INF/web2.xml"); + addComponent(existing); + addComponent(nonExisting); + + } + + private Button createButton(final String filename) { + Button b = new Button("Download " + filename); + b.addListener(new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + FileResource res = new FileResource(new File(getContext() + .getBaseDirectory() + + "/" + filename), NonExistingFileResource.this); + getMainWindow().open(res); + + } + }); + return b; + } + + @Override + protected String getDescription() { + // TODO Auto-generated method stub + return null; + } + + @Override + protected Integer getTicketNumber() { + // TODO Auto-generated method stub + return null; + } + +} -- 2.39.5