Ticket #151 (closed defect: fixed)
StringLengthValidator bugs
| Reported by: | Joonas Lehtinen | Owned by: | Jani Laakso |
|---|---|---|---|
| Priority: | undefined | Milestone: | User Interface Library 5.2.0 RC |
| Component: | Testing | Version: | |
| Keywords: | Cc: | ||
| Known Issue description: | |||
| Hours estimate: | Deadline (dd.mm.yyyy): | ||
| Known Issue version (since): | Known Issue title: | ||
| Hours done: | Depends to: | ||
| Affects documentation: | no | ||
| Known Issue workaround: | |||
| Affects release notes: | no | Contract: | |
Description
Confirm
http://bugzilla.millstone.org/show_bug.cgi?id=648
Description: Opened: 2003-07-15 21:04 This is from version 3.0.3 If you try to validate a value with StringLengthValidator?, and this value allows null, the validation fails with NullPointerException?. This is because "null allowed" is not handled. I did the correction from this...
public void validate(Object value) throws Validator.InvalidValueException? {
if (value == null && !allowNull)
throw new Validator.InvalidValueException?(errorMessage);
// the line below is where the error occurs, because value is null String s = value.toString(); if (s == null && !allowNull)
throw new Validator.InvalidValueException?(errorMessage);
// the line below would cause the same error int len = s.length(); if ((minLength >= 0 && len < minLength)
(maxLength >= 0 && len > maxLength)) throw new Validator.InvalidValueException?(errorMessage);
}
to this...
public void validate(Object value) throws Validator.InvalidValueException? {
if (value == null && !allowNull)
throw new Validator.InvalidValueException?(errorMessage);
String s = (value == null ? null : value.toString()); if (s == null && !allowNull)
throw new Validator.InvalidValueException?(errorMessage);
int len = (s == null ? 0 : s.length()); if ((minLength >= 0 && len < minLength)
(maxLength >= 0 && len > maxLength)) throw new Validator.InvalidValueException?(errorMessage);
}
The same will happen to the isValid() method, as it has the same code.
Hope it helps.
