]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix client-side NPE in Image without a source (#10101) 93/193/2
authorJohannes Dahlström <johannesd@vaadin.com>
Thu, 1 Nov 2012 11:12:07 +0000 (13:12 +0200)
committerVaadin Code Review <review@vaadin.com>
Thu, 1 Nov 2012 12:04:37 +0000 (12:04 +0000)
Change-Id: I7911dffd8700dc166f7b8669d291a0e34cb43daf

client/src/com/vaadin/client/ui/image/ImageConnector.java
uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/abstractembedded/EmbeddedWithNullSource.java [new file with mode: 0644]

index 22067b051e8fa975ec3b9432c8243f0088de2e68..17ce058c5de517ed769e7f4849a16b9398ebf04b 100644 (file)
@@ -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 (file)
index 0000000..37186bd
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="" />
+<title>EmbeddedWithNullSource</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">EmbeddedWithNullSource</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/EmbeddedWithNullSource?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..e6b5139
--- /dev/null
@@ -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;
+    }
+
+}