rootvector2 commented on code in PR #404:
URL: https://github.com/apache/commons-beanutils/pull/404#discussion_r3477724572
##########
src/main/java/org/apache/commons/beanutils2/converters/NumberConverter.java:
##########
@@ -457,6 +463,9 @@ private <T> T toNumber(final Class<?> sourceType, final
Class<T> targetType, fin
if (value.doubleValue() > Float.MAX_VALUE) {
throw ConversionException.format("%s value '%s' is too large
for %s", toString(sourceType), value, toString(targetType));
}
+ if (value.doubleValue() < -Float.MAX_VALUE) {
Review Comment:
`Float.MIN_VALUE` is the smallest positive value (`1.4E-45`), not the most
negative one, so it can't serve as the lower bound. The most negative finite
float is `-Float.MAX_VALUE`. The `Long` branch above can use `Long.MIN_VALUE`
because for integral types that is the most negative value, but for floating
point types it isn't.
##########
src/test/java/org/apache/commons/beanutils2/converters/FloatConverterTest.java:
##########
@@ -70,11 +70,17 @@ void testInvalidAmount() {
final Converter<Float> converter = makeConverter();
final Class<?> clazz = Float.class;
final Double max = Double.valueOf(Float.MAX_VALUE);
+ final Double min = Double.valueOf(-Float.MAX_VALUE);
final Double tooBig = Double.valueOf(Double.MAX_VALUE);
+ final Double tooSmall = Double.valueOf(-Double.MAX_VALUE);
// Maximum
assertEquals(Float.valueOf(Float.MAX_VALUE), converter.convert(clazz,
max), "Maximum");
+ // Minimum
+ assertEquals(Float.valueOf(-Float.MAX_VALUE), converter.convert(clazz,
min), "Minimum");
Review Comment:
Same reason as in the converter: `Float.MIN_VALUE` is the smallest positive
value, not the most negative, so the lowest representable float is
`-Float.MAX_VALUE`.
--
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]