You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "sahvx655-wq (via GitHub)" <gi...@apache.org> on 2026/06/03 17:27:49 UTC
[PR] reject NaN and infinity in double and float validators [commons-validator]
sahvx655-wq opened a new pull request, #384:
URL: https://github.com/apache/commons-validator/pull/384
reading the number validators, validate of double and float passes the parsed value straight through processParsedValue without checking it is finite. NumberFormat recognises the locale NaN and infinity symbols, so validate("NaN"), validate("∞") and validate("-∞") return NaN/infinity and isValid returns true. a NaN that validates then silently defeats every isInRange/minValue/maxValue check, since NaN compares false against everything. reject non-finite results in both validators.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "sahvx655-wq (via GitHub)" <gi...@apache.org>.
sahvx655-wq commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4639215865
ah I get it now, you wanted them accepted so they're all consistent, not rejected. I read it backwards. thanks for sorting it in #388. still pretty new to this stuff but learning, appreciate the patience.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "sahvx655-wq (via GitHub)" <gi...@apache.org>.
sahvx655-wq commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4622193536
fair point. NaN is a legitimate Double value and NumberFormat parses it by design, so rejecting it here is a behaviour change that could break callers who genuinely want to validate it. my reasoning was that a NaN which passes then slips past every isInRange/minValue check, since NaN compares false against everything, but on reflection that guard belongs to the caller, not this class. and as you spotted the infinity handling is already inconsistent (NaN and the ∞ symbol parse, +Infinity doesn't), which isn't something to paper over in this PR. happy to close this out, your edge-case test updates already pin the current behaviour as the sensible default.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4622258754
Also note that NaN parsing behavior is different on Java 8 compared to newer versions.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory closed pull request #384: reject NaN and infinity in double and float validators
URL: https://github.com/apache/commons-validator/pull/384
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4631397544
Do you think it is worth fixing the `Double.[POSITIVE|NEGATIVE]_INFINITY` cases?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "sahvx655-wq (via GitHub)" <gi...@apache.org>.
sahvx655-wq commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4632700597
Yes, I think the infinity cases are worth closing. I traced the parse with a ParsePosition under Locale.US: the "Infinity"/"-Infinity" strings throw a ParseException so validate already returns null, but the locale infinity symbol (the U+221E glyph) parses with full consumption straight to POSITIVE_INFINITY, so the strict check passes and validate hands back an infinite Double. Same value, two spellings, opposite outcomes, which is the discrepancy you pointed at.
So I've narrowed this PR to reject only infinite results in both processParsedValue methods and left NaN exactly as your edge-case tests pin it, since that one is symmetric and a legitimate value to validate. The risk if left is the same shape as the NaN one: an infinite value sails past isInRange/maxValue because the comparisons don't bound it, but here there's no matching "Infinity" string that validates, so nothing legitimate relies on the symbol getting through. Added a test in each class that derives the symbol from DecimalFormatSymbols so it follows the locale, and no JRE guard is needed because on Java 8 the symbol just fails to parse and still returns null.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4636390088
Somehow, you or your AI tool the opposite of my meaning. Instead of this frustrating loop, I created https://github.com/apache/commons-validator/pull/388 and will close this PR.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4639608968
YW. Your help is greatly appreciated 👏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] reject NaN and infinity in double and float validators [commons-validator]
Posted by "garydgregory (via GitHub)" <gi...@apache.org>.
garydgregory commented on PR #384:
URL: https://github.com/apache/commons-validator/pull/384#issuecomment-4621628824
@sahvx655-wq
Did you read the Javadoc?
This looks like you or your AI are imagining requirements that don't exist or that I can't find.
For example, "NaN" is a valid value to parse with a `NumberFormat` (which we use):
```
jshell> import java.text.*;
jshell> NumberFormat.getInstance().parse("NaN");
$3 ==> NaN
```
But it's not the same for `Double.POSITIVE_INFINITY`:
```
jshell> NumberFormat.getInstance().parse("" + Double.POSITIVE_INFINITY)
| Exception java.text.ParseException: Unparseable number: "+Infinity"
| at NumberFormat.parse (NumberFormat.java:434)
| at (#2:1)
```
So there is a discrepancy...
Aside from the issue that the PR this may break existing applications, how do you propose an app use this class to validate, for example, config file values, or user input where in fact, a Double value like `Double.NaN` is expected?
FYI, I updated tests for edge case tests in `FloatValidatorTest` and `DoubleValidatorTest` to reflect the current code.
TY!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org