Files
floci/src/test/java
Allen Sanborn bd436eeea1 fix(msk): reject numberOfBrokerNodes values that only look whole after double rounding (#2571)
asBrokerCount validated the incoming JSON number by parsing it as a double and
comparing d == Math.rint(d), but a literal like 1.0000000000000001 has no exact
double representation and collapses to precisely 1.0 during that conversion -
so the check ran after the precision that would have caught it was already
gone, and malformed input was silently accepted as a valid integer.

Binding numberOfBrokerNodes straight to Integer isn't a fix either: Jackson's
default float-to-int coercion truncates a JSON float token the same way
intValue() would, reintroducing the exact bug this field's validation exists
to prevent.

BrokerCountDeserializer reads the token as an exact BigDecimal via
JsonParser#getDecimalValue(), which Jackson builds directly from the source
text rather than routing through a lossy double, so it can tell a genuinely
fractional literal from one that only looks fractional (or only looks whole)
after floating-point rounding.

It can't throw directly on malformed input, though: an exception raised while
Jackson is still reading the request body is caught by
ServerJacksonMessageBodyReader before the JAX-RS resource method - and this
service's AwsException/AwsExceptionMapper handling - ever run, producing a
bodyless 400 instead of MSK's usual {message, invalidParameter} shape.
BrokerCount carries "malformed" as a value instead, and
MskService#validateCreateRequest raises the proper error once binding has
finished successfully, the same way it already does for every other
CreateCluster validation failure.
2026-08-27 13:08:28 -04:00
..