Skip to content

fix: restrict isNumeric() to ASCII digits to prevent NumberFormatExceptionRefactor digit validation logic in MavenArchiver#376

Merged
elharo merged 2 commits into
apache:masterfrom
HarshMehta112:fix/#365
Jul 2, 2026
Merged

fix: restrict isNumeric() to ASCII digits to prevent NumberFormatExceptionRefactor digit validation logic in MavenArchiver#376
elharo merged 2 commits into
apache:masterfrom
HarshMehta112:fix/#365

Conversation

@HarshMehta112

@HarshMehta112 HarshMehta112 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Fixes : #365

Problem

The isNumeric() method currently uses Character.isDigit(), which returns true for many non-ASCII Unicode digits (such as Arabic-Indic ٠١٢٣, Bengali ০১২৩, and Devanagari ०१२३).

When parseBuildOutputTimestamp() receives one of these values through project.build.outputTimestamp or SOURCE_DATE_EPOCH, isNumeric() incorrectly treats it as a valid numeric string. The value is then passed to Long.parseLong() (around line 697), which only accepts ASCII digits (0–9) and throws a NumberFormatException.

Since the method only catches DateTimeParseException (around line 708), the NumberFormatException propagates uncaught, causing archive creation to fail with an unhelpful error message.

Fix

Replace the use of Character.isDigit() with an explicit ASCII digit check:

c >= '0' && c <= '9'

Following this checklist to help us incorporate your
contribution quickly and easily:

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • 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 is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>
Signed-off-by: Harsh Mehta <harshmehta010102@gmail.com>

for (char c : str.toCharArray()) {
if (!Character.isDigit(c)) {
if (c < '0' || c > '9') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally I prefer

c >= '0' && c <= '9'

but either way is fine

@elharo elharo merged commit 785d928 into apache:master Jul 2, 2026
8 checks passed
@github-actions github-actions Bot added this to the 4.0.0-beta-5 milestone Jul 2, 2026
@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

@elharo Please assign appropriate label to PR according to the type of change.

@elharo elharo added bug Something isn't working java Pull requests that update Java code labels Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working java Pull requests that update Java code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

isNumeric() accepts non-ASCII digits causing NumberFormatException in parseBuildOutputTimestamp

2 participants