From 940d7bf02abc0997eabc4cda12157ad2ceedfcf7 Mon Sep 17 00:00:00 2001 From: Florian Schmaus Date: Mon, 27 Dec 2021 21:17:57 +0100 Subject: [PATCH] [xdata] Adjust behavior of BooleanFormField.getValueAsBoolean() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to XEP-0004 § 3.3, the default value of a boolean form field is 'false'. And since users are typically interested in getting the value, and not potentially 'null' as result, we adjust the behavior of the getValueAsBoolean() method consider the default value. --- .../jivesoftware/smackx/xdata/BooleanFormField.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java index 85e351649..6208e4979 100644 --- a/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java +++ b/smack-extensions/src/main/java/org/jivesoftware/smackx/xdata/BooleanFormField.java @@ -35,7 +35,17 @@ public class BooleanFormField extends SingleValueFormField { return value.toString(); } - public Boolean getValueAsBoolean() { + /** + * Get the value of the booelan field. Note that, if no explicit boolean value is provided, in the form of "true", + * "false", "0", or "1", then the default value of a boolean field is false, according to + * XEP-0004 § 3.3. + * + * @return the boolean value of this form field. + */ + public boolean getValueAsBoolean() { + if (value == null) { + return false; + } return value; }