garydgregory commented on code in PR #431:
URL: https://github.com/apache/commons-cli/pull/431#discussion_r3591507453
##########
src/main/java/org/apache/commons/cli/Converter.java:
##########
@@ -60,7 +61,16 @@ public interface Converter<T, E extends Exception> {
/**
* Converts a String to a {@link Number}. Converts to a Double if a
decimal point ('.') is in the string or a Long otherwise.
*/
- Converter<Number, NumberFormatException> NUMBER = s -> s.indexOf('.') !=
-1 ? (Number) Double.valueOf(s) : (Number) Long.valueOf(s);
+ Converter<Number, NumberFormatException> NUMBER = s -> {
+ if (s.indexOf('.') != -1) {
+ // Double.valueOf() also accepts hexadecimal floating point
(0x1.8p1), type suffixes (1.0d, 1.0f)
+ // and surrounding whitespace; validate with a strict BigDecimal
parse so those are rejected like
+ // the Long branch already rejects them.
+ new BigDecimal(s);
+ return Double.valueOf(s);
Review Comment:
Why not just:
```suggestion
return new BigDecimal(s).doubleValue()
```
?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]