Skip to content

Validators do not handle null input #67

@nibsky

Description

@nibsky

For example in IntegerRangeValidator:

public class IntegerRangeValidator extends CustomValidator<Integer> {

    private IntegerRangeValidator(int min, int max, String errorMessage) {
        super(input -> input >= min && input <= max, errorMessage);
    }
 ....

Could be:

public class IntegerRangeValidator extends CustomValidator<Integer> {

    private IntegerRangeValidator(int min, int max, String errorMessage) {
        super(input -> null != input && input >= min && input <= max, errorMessage);
    }
 ....

Some background on my usage:
I had set the IntegerRangeValidator into a SingleSelectionField (Selection bound to an IntegerProperty).
Due to some design constraint, I needed to change the SingleSelectionField content using SingleSelectionField.items(List).. This part nullifies the bound IntegerProperty until I use SingleSelectionField.select(0).
This causes an unhandled NullPointerException.

Kindly correct me if I overlooked a better approach.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions