Skip to content
Permalink
Browse files
reject NaN for number sign validations
  • Loading branch information
mbenson committed Oct 16, 2018
1 parent e5278cd commit 3c36eb16ac1ba667a8109eb5ea3c8609ac00ef26
Showing 1 changed file with 10 additions and 3 deletions.
@@ -57,16 +57,23 @@ public ForNegative() {
super(n -> n < 0);
}
}

private final IntPredicate comparisonTest;

protected NumberSignValidator(IntPredicate comparisonTest) {
super();
this.comparisonTest = Validate.notNull(comparisonTest);
}

@Override
public boolean isValid(Number value, ConstraintValidatorContext context) {
return value == null || comparisonTest.test(Double.compare(value.doubleValue(), 0.0));
if (value == null) {
return true;
}
final double d = value.doubleValue();
if (Double.isNaN(d)) {
return false;
}
return comparisonTest.test(Double.compare(d, 0.0));
}
}

0 comments on commit 3c36eb1

Please sign in to comment.