From 2042ac08fa22e4f3c827b3fac5ac255f7076cac0 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Tue, 3 May 2011 11:34:43 +0000 Subject: [PATCH] #6918 CheckBox/Button in switch mode should support null value svn changeset:18604/svn branch:6.6 --- src/com/vaadin/ui/Button.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java index 8fa9e2afb9..c64cd386ce 100644 --- a/src/com/vaadin/ui/Button.java +++ b/src/com/vaadin/ui/Button.java @@ -188,7 +188,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, } // If the button is true for some reason, release it - if (oldValue.booleanValue()) { + if (null == oldValue || oldValue.booleanValue()) { setValue(Boolean.FALSE); } } @@ -240,13 +240,8 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, * @return True iff the button is pressed down or checked. */ public boolean booleanValue() { - boolean state; - try { - state = ((Boolean) getValue()).booleanValue(); - } catch (final NullPointerException e) { - state = false; - } - return state; + Boolean value = (Boolean) getValue(); + return (null == value) ? false : value.booleanValue(); } /** @@ -475,7 +470,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier, @Override protected void setInternalValue(Object newValue) { // Make sure only booleans get through - if (!(newValue instanceof Boolean)) { + if (null != newValue && !(newValue instanceof Boolean)) { throw new IllegalArgumentException(getClass().getSimpleName() + " only accepts Boolean values"); } -- 2.39.5