alhudz opened a new pull request, #1833:
URL: https://github.com/apache/commons-lang/pull/1833
Repro: `NumberUtils.createNumber(" 1.5")`, `createNumber("\t1e5")`,
`createNumber(" 1.5d")`, or `isCreatable(" 1.5")`.
Expected: `NumberFormatException` from `createNumber` and `false` from
`isCreatable`. The `createNumber` Javadoc says it does not trim the input and
that leading or trailing spaces produce a `NumberFormatException`, and
`createNumber(" 1111")` does throw.
Actual: `1.5` (`Float`), `100000.0` (`Float`), `1.5` (`Double`) and `true`.
Cause: the integral paths reject whitespace because `Integer.decode`,
`Long.decode` and `BigInteger` do, but any input with a decimal point, an
exponent or an `f`/`F`/`d`/`D` suffix is handed to `Float.valueOf` and
`Double.valueOf`, which strip leading characters up to U+0020 as if by
`String.trim()`. The leading character is only inspected for a sign, so the
whitespace rides along into the delegate. Trailing whitespace is already caught
because it is taken as an unknown type suffix.
Fix: reject a leading character at or below U+0020 in `createNumber` before
any delegate is reached, so the decimal paths behave like the integral paths
and the Javadoc. `isCreatable` and the deprecated `isNumber` delegate to
`createNumber`, so they are covered by the same check. Valid input, and
trailing whitespace, are unchanged.
Regression assertions added next to the existing `" 1111"` cases in
`NumberUtilsTest.testIsCreatable` and `testIsNumber`; both tests fail before
the change (`Expecting false for isCreatable/createNumber using " 1.5" but got
true and true`) and pass after. There is no Commons Text counterpart of
`NumberUtils` to check.
- [x] Read the [contribution guidelines](CONTRIBUTING.md) for this project.
- [x] Read the [ASF Generative Tooling
Guidance](https://www.apache.org/legal/generative-tooling.html) if you use
Artificial Intelligence (AI).
- [x] I used AI to create any part of, or all of, this pull request. Which
AI tool was used to create this pull request, and to what extent did it
contribute? Claude Code (Anthropic) found the issue, wrote the patch and the
test assertions, and ran the build; I reviewed the change before submitting.
- [x] Run a successful build using the default
[Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command
line by itself.
- [x] Write unit tests that match behavioral changes, where the tests fail
if the changes to the runtime are not applied. This may not always be possible,
but it is a best practice.
- [x] Write a pull request description that is detailed enough to understand
what the pull request does, how, and why.
- [x] Each commit in the pull request should have a meaningful subject line
and body. Note that a maintainer may squash commits during the merge process.
--
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]