From 02a808548472a8aa66631fdbf5ee119b24061a92 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 16 Nov 2012 17:24:54 +0200 Subject: [PATCH] Fix NPE when removing FileDownloader (#10198) Change-Id: I2423e3fbe88becfd76ed17c15d911d9253bf6e35 --- .../extensions/FileDownloaderConnector.java | 2 +- .../tests/components/FileDownloaderTest.html | 36 +++++++++++++++++++ .../tests/components/FileDownloaderTest.java | 36 ++++++++++++++++++- 3 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/FileDownloaderTest.html diff --git a/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java b/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java index 6308de9c05..61a8bee9d3 100644 --- a/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java +++ b/client/src/com/vaadin/client/extensions/FileDownloaderConnector.java @@ -69,7 +69,7 @@ public class FileDownloaderConnector extends AbstractExtensionConnector @Override public void setParent(ServerConnector parent) { super.setParent(parent); - if (parent == null) { + if (parent == null && iframe != null) { iframe.removeFromParent(); } } diff --git a/uitest/src/com/vaadin/tests/components/FileDownloaderTest.html b/uitest/src/com/vaadin/tests/components/FileDownloaderTest.html new file mode 100644 index 0000000000..bfe87091cc --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/FileDownloaderTest.html @@ -0,0 +1,36 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.FileDownloaderTest?restartApplication
assertElementPresentvaadin=runcomvaadintestscomponentsFileDownloaderTest::PID_Scom.vaadin.ui.ButtonDynamicimage/domChild[0]/domChild[0]
clickvaadin=runcomvaadintestscomponentsFileDownloaderTest::/VVerticalLayout[0]/VOrderedLayout$Slot[1]/VVerticalLayout[0]/VOrderedLayout$Slot[4]/VButton[0]/domChild[0]/domChild[0]
assertElementNotPresentvaadin=runcomvaadintestscomponentsFileDownloaderTest::PID_Scom.vaadin.ui.ButtonDynamicimage/domChild[0]/domChild[0]
+ + diff --git a/uitest/src/com/vaadin/tests/components/FileDownloaderTest.java b/uitest/src/com/vaadin/tests/components/FileDownloaderTest.java index e773c8c75b..55d2afd32d 100644 --- a/uitest/src/com/vaadin/tests/components/FileDownloaderTest.java +++ b/uitest/src/com/vaadin/tests/components/FileDownloaderTest.java @@ -37,6 +37,7 @@ import com.vaadin.server.StreamResource; import com.vaadin.server.VaadinRequest; import com.vaadin.server.VaadinResponse; import com.vaadin.tests.components.embedded.EmbeddedPdf; +import com.vaadin.tests.util.Log; import com.vaadin.ui.AbstractComponent; import com.vaadin.ui.Button; import com.vaadin.ui.Button.ClickEvent; @@ -45,12 +46,18 @@ import com.vaadin.ui.Component; import com.vaadin.ui.CssLayout; import com.vaadin.ui.HorizontalLayout; import com.vaadin.ui.Label; +import com.vaadin.ui.Layout; import com.vaadin.ui.NativeButton; public class FileDownloaderTest extends AbstractTestUI { + private AbstractComponent firstDownloadComponent; + private Log log = new Log(5); + @Override protected void setup(VaadinRequest request) { + addComponent(log); + List> components = new ArrayList>(); components.add(Button.class); components.add(NativeButton.class); @@ -104,6 +111,29 @@ public class FileDownloaderTest extends AbstractTestUI { // addComponents(resource, components); resource = new ClassResource(new EmbeddedPdf().getClass(), "test.pdf"); addComponents("Class resource pdf", resource, components); + + addComponent(new Button("Remove first download button", + new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + Layout parent = (Layout) firstDownloadComponent + .getParent(); + parent.removeComponent(firstDownloadComponent); + } + })); + addComponent(new Button( + "Detach FileDownloader from first download button", + new ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + FileDownloader e = (FileDownloader) firstDownloadComponent + .getExtensions().iterator().next(); + e.removeFromTarget(); + log.log("FileDownload detached"); + } + })); } public void addComponents(String caption, ConnectorResource resource, @@ -113,7 +143,11 @@ public class FileDownloaderTest extends AbstractTestUI { for (Class cls : components) { try { AbstractComponent c = (AbstractComponent) cls.newInstance(); - c.setId(cls.getName()); + if (firstDownloadComponent == null) { + firstDownloadComponent = c; + } + + c.setId(cls.getName() + caption.replace(" ", "")); c.setCaption(cls.getName()); c.setDescription(resource.getMIMEType() + " / " + resource.getClass()); -- 2.39.5