Skip to content

Support positive hexadecimal values in NumberUtils - #37434

Merged
sbrannen merged 1 commit into
spring-projects:mainfrom
EsmaeilChitgar:fix/numberutils-positive-hex-prefix
Oct 10, 2026
Merged

sbrannen merged 1 commit into
spring-projects:mainfrom
EsmaeilChitgar:fix/numberutils-positive-hex-prefix

Conversation

@EsmaeilChitgar

@EsmaeilChitgar EsmaeilChitgar commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Overview

This PR updates NumberUtils.parseNumber() to support hexadecimal numbers prefixed with a plus sign.

Problem

For example:

NumberUtils.parseNumber("+0x7f", Integer.class);

Previously, this resulted in a NumberFormatException, despite the corresponding JDK decoding methods accepting this representation.

Solution

  • Recognize an optional leading plus sign during hexadecimal detection.
  • Handle the same syntax in BigInteger parsing.
  • Add regression tests for the affected numeric types.

Testing

Regression tests have been added to NumberUtilsTests.

The change is intended to preserve existing parsing behavior for other numeric formats.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 9, 2026
@sbrannen sbrannen self-assigned this Oct 9, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 9, 2026
Signed-off-by: Esmaeil Chitgar <ec.chitgar@gmail.com>
@EsmaeilChitgar
EsmaeilChitgar force-pushed the fix/numberutils-positive-hex-prefix branch from a8f0e8e to a5a9e73 Compare October 10, 2026 04:38
@sbrannen sbrannen changed the title Support positive hexadecimal values in NumberUtils Support positive hexadecimal values in NumberUtils Oct 10, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 10, 2026
@sbrannen sbrannen added this to the 7.1.0-RC1 milestone Oct 10, 2026
@sbrannen
sbrannen merged commit 3e05e88 into spring-projects:main Oct 10, 2026
1 check passed
sbrannen added a commit that referenced this pull request Oct 10, 2026
@sbrannen

Copy link
Copy Markdown
Member

Hi @EsmaeilChitgar,

Good catch and congratulations on submitting your first PR for the Spring Framework! 👍

This has been merged into main in 3e05e88 and slightly revised in cb98dd3.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants