Ticket #151 (closed defect: fixed)

Opened 23 months ago

Last modified 7 months ago

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.

Change History

Changed 23 months ago by Joonas Lehtinen

  • summary changed from StringLengthValidator fails to validade null value to StringLengthValidator bugs

Another one?

http://bugzilla.millstone.org/show_bug.cgi?id=677

Description: Opened: 2005-01-16 23:25 Jari reported on forum that. Unchecked:

isValid and validate functions are broken.

isValid is currently as follows:

Code:

if (value == null && !allowNull)

return true; String s = value.toString(); if (s == null && !allowNull)

return true;

int len = s.length(); if ((minLength >= 0 && len < minLength)

(maxLength >= 0 && len > maxLength))

return false;

return true;

It should be more like this:

Code:

if (value == null) {

if (allowNull) return true; return false;

} String s = value.toString(); if (s == null) {

if (allowNull) return true; return false;

} int len = s.length();

if ((minLength >= 0 && len < minLength) (maxLength >= 0 && len > maxLength)) return false; return true;

And the validate function should be more like this:

Code:

if (value == null) {

if (!allowNull) throw new Validator.InvalidValueException?(errorMessage); return;

} String s = value.toString(); if (s == null) {

if (!allowNull) throw new Validator.InvalidValueException?(errorMessage); return;

} int len = s.length();

if ((minLength >= 0 && len < minLength) (maxLength >= 0 && len > maxLength)) throw new Validator.InvalidValueException?(errorMessage);

This is with the newest code from CVS.

Changed 10 months ago by Joonas Lehtinen

  • milestone set to User Interface Library 5.1.0 RC
  • affects_documentation unset
  • affects_release_notes unset

Changed 9 months ago by Joonas Lehtinen

  • priority changed from trivial to undefined

Changed 9 months ago by Marc Englund

  • status changed from new to closed
  • resolution set to fixed

Fixed in [3910]

Changed 7 months ago by Joonas Lehtinen

  • milestone changed from User Interface Library 5.1.2 to User Interface Library 5.2.0

Milestone User Interface Library 5.1.2 deleted

Note: See TracTickets for help on using tickets.