From 47b7f536b28305914d40812e2a97eb99ec836eef Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Mon, 4 Jan 2016 14:42:05 +0200 Subject: Fix NPE in Label.writeDesign with NULL values #19434 Change-Id: If3628bc655d6cd58ab51b7400af808bdbca3dc91 --- server/src/com/vaadin/ui/Label.java | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'server/src') diff --git a/server/src/com/vaadin/ui/Label.java b/server/src/com/vaadin/ui/Label.java index 2b96d51fa5..1498246ec5 100644 --- a/server/src/com/vaadin/ui/Label.java +++ b/server/src/com/vaadin/ui/Label.java @@ -625,12 +625,31 @@ public class Label extends AbstractComponent implements Property, super.writeDesign(design, designContext); String content = getValue(); if (content != null) { - design.html(getValue()); - } - // plain-text (default is html) - if (getContentMode() == ContentMode.TEXT) { - design.attr(DESIGN_ATTR_PLAIN_TEXT, true); - design.html(DesignFormatter.encodeForTextNode(getValue())); + switch (getContentMode()) { + case TEXT: + case PREFORMATTED: + case XML: + case RAW: { + // FIXME This attribute is not enough to be able to restore the + // content mode in readDesign. The content mode should instead + // be written directly in the attribute and restored in + // readDesign. See ticket #19435 + design.attr(DESIGN_ATTR_PLAIN_TEXT, true); + String encodeForTextNode = DesignFormatter + .encodeForTextNode(content); + if (encodeForTextNode != null) { + design.html(encodeForTextNode); + } + } + break; + case HTML: + design.html(content); + break; + default: + throw new IllegalStateException( + "ContentMode " + getContentMode() + + " is not supported by writeDesign"); + } } } } -- cgit v1.2.3