From: Artur Signell Date: Mon, 16 Feb 2015 20:10:15 +0000 (+0200) Subject: Properly handle null in critical notifications (#16592) X-Git-Tag: 7.4.1~60 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a6679efa9449e96048f6c0263f0f617f76bc8e3b;p=vaadin-framework.git Properly handle null in critical notifications (#16592) Change-Id: I85994e47f99e2ac5431e67c56f432380e84af23d --- diff --git a/server/src/com/vaadin/server/VaadinService.java b/server/src/com/vaadin/server/VaadinService.java index 36d6910a7a..2aaab31dd1 100644 --- a/server/src/com/vaadin/server/VaadinService.java +++ b/server/src/com/vaadin/server/VaadinService.java @@ -1581,8 +1581,18 @@ public abstract class VaadinService implements Serializable { } JsonObject appError = Json.createObject(); - appError.put("caption", caption); - appError.put("message", message); + if (caption == null) { + appError.put("caption", Json.createNull()); + } else { + appError.put("caption", caption); + } + + if (message == null) { + appError.put("message", Json.createNull()); + } else { + appError.put("message", message); + } + if (url == null) { appError.put("url", Json.createNull()); } else { diff --git a/server/tests/src/com/vaadin/server/VaadinServiceTest.java b/server/tests/src/com/vaadin/server/VaadinServiceTest.java index 51325067d2..c2ca8b0e57 100644 --- a/server/tests/src/com/vaadin/server/VaadinServiceTest.java +++ b/server/tests/src/com/vaadin/server/VaadinServiceTest.java @@ -66,4 +66,18 @@ public class VaadinServiceTest { Assert.assertEquals("SessionDestroyListeners not called exactly once", 1, listener.callCount); } + + @Test + public void testCriticalNotificationNullHandling() { + for (String caption : new String[] { "some caption", null }) { + for (String message : new String[] { "some message", null }) { + for (String details : new String[] { "some details", null }) { + for (String url : new String[] { "some url", null }) { + VaadinService.createCriticalNotificationJSON(caption, + message, details, url); + } + } + } + } + } }