From 9db16de4a74823f733f62dc9a213cc851d911260 Mon Sep 17 00:00:00 2001 From: Marc Englund Date: Mon, 25 Feb 2008 10:16:28 +0000 Subject: [PATCH] Does not choke on null:s anymore, fixes #151 svn changeset:3910/svn branch:trunk --- .../data/validator/StringLengthValidator.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/com/itmill/toolkit/data/validator/StringLengthValidator.java b/src/com/itmill/toolkit/data/validator/StringLengthValidator.java index b622ea08ed..05fc6b610c 100644 --- a/src/com/itmill/toolkit/data/validator/StringLengthValidator.java +++ b/src/com/itmill/toolkit/data/validator/StringLengthValidator.java @@ -67,12 +67,20 @@ public class StringLengthValidator implements Validator { * if the value was invalid. */ public void validate(Object value) throws Validator.InvalidValueException { - if (value == null && !allowNull) { - throw new Validator.InvalidValueException(errorMessage); + if (value == null) { + if (allowNull) { + return; + } else { + throw new Validator.InvalidValueException(errorMessage); + } } final String s = value.toString(); - if (s == null && !allowNull) { - throw new Validator.InvalidValueException(errorMessage); + if (s == null) { + if (allowNull) { + return; + } else { + throw new Validator.InvalidValueException(errorMessage); + } } final int len = s.length(); if ((minLength >= 0 && len < minLength) @@ -89,12 +97,12 @@ public class StringLengthValidator implements Validator { * @return true for valid value, otherwise false. */ public boolean isValid(Object value) { - if (value == null && !allowNull) { - return true; + if (value == null) { + return allowNull; } final String s = value.toString(); - if (s == null && !allowNull) { - return true; + if (s == null) { + return allowNull; } final int len = s.length(); if ((minLength >= 0 && len < minLength) -- 2.39.5