From dbf982bb3b3ddccba00fbc889a0130feac2a6d2d Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Thu, 1 Nov 2012 13:12:07 +0200 Subject: [PATCH] Fix client-side NPE in Image without a source (#10101) Change-Id: I7911dffd8700dc166f7b8669d291a0e34cb43daf --- .../client/ui/image/ImageConnector.java | 9 ++-- .../EmbeddedWithNullSource.html | 27 +++++++++++ .../EmbeddedWithNullSource.java | 48 +++++++++++++++++++ 3 files changed, 81 insertions(+), 3 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.html create mode 100644 uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.java diff --git a/client/src/com/vaadin/client/ui/image/ImageConnector.java b/client/src/com/vaadin/client/ui/image/ImageConnector.java index 22067b051e..17ce058c5d 100644 --- a/client/src/com/vaadin/client/ui/image/ImageConnector.java +++ b/client/src/com/vaadin/client/ui/image/ImageConnector.java @@ -48,9 +48,12 @@ public class ImageConnector extends AbstractComponentConnector { clickEventHandler.handleEventHandlerRegistration(); - getWidget().setUrl( - getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE)); - getWidget().setAltText(getState().alternateText); + String url = getResourceUrl(AbstractEmbeddedState.SOURCE_RESOURCE); + getWidget().setUrl(url != null ? url : ""); + + String alt = getState().alternateText; + // Some browsers turn a null alt text into a literal "null" + getWidget().setAltText(alt != null ? alt : ""); } protected final ClickEventHandler clickEventHandler = new ClickEventHandler( diff --git a/uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.html b/uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.html new file mode 100644 index 0000000000..37186bd901 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.html @@ -0,0 +1,27 @@ + + + + + + +EmbeddedWithNullSource + + + + + + + + + + + + + + + + + +
EmbeddedWithNullSource
open/run/EmbeddedWithNullSource?restartApplication
screenCapture
+ + diff --git a/uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.java b/uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.java new file mode 100644 index 0000000000..e6b51399e9 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.java @@ -0,0 +1,48 @@ +package com.vaadin.tests.components.abstractembedded; + +import com.vaadin.tests.components.TestBase; +import com.vaadin.ui.AbstractEmbedded; +import com.vaadin.ui.BrowserFrame; +import com.vaadin.ui.Flash; +import com.vaadin.ui.Image; + +public class EmbeddedWithNullSource extends TestBase { + + @Override + protected void setup() { + AbstractEmbedded e; + + e = new Image("Image w/o alt text"); + addComponent(e); + + e = new Image("Image w/ alt text"); + e.setAlternateText("Image"); + addComponent(e); + + e = new Flash("Flash w/o alt text"); + addComponent(e); + + e = new Flash("Flash w/ alt text"); + e.setAlternateText("Flash"); + addComponent(e); + + e = new BrowserFrame("BrowserFrame w/o alt text"); + addComponent(e); + + e = new BrowserFrame("BrowserFrame w/ alt text"); + e.setAlternateText("BrowserFrame"); + addComponent(e); + + } + + @Override + protected String getDescription() { + return "Image without a source causes a client-side NPE"; + } + + @Override + protected Integer getTicketNumber() { + return 10101; + } + +} -- 2.39.5