Skip to content

Fix test parameter parsing treating leading-zero strings as octal#38569

Open
daguimu wants to merge 1 commit intoapache:masterfrom
daguimu:fix/test-parameter-octal-parsing-31001
Open

Fix test parameter parsing treating leading-zero strings as octal#38569
daguimu wants to merge 1 commit intoapache:masterfrom
daguimu:fix/test-parameter-octal-parsing-31001

Conversation

@daguimu
Copy link
Copy Markdown

@daguimu daguimu commented Mar 27, 2026

Problem

SQLRewriteEngineTestParametersBuilder.createInputParameter() uses NumberUtils.createNumber() to parse test parameter strings. When a parameter string consists entirely of digits but starts with '0' (e.g., encrypted phone number 04844448888), NumberUtils.createNumber() interprets it as an octal literal per Java conventions, throwing NumberFormatException since digits 8 and 9 are invalid in octal.

Even for valid octal-looking strings like 04100001111 (digits 0-7 only), the value is silently parsed as octal instead of decimal, producing a wrong numeric value.

Root Cause

StringUtils.isNumeric("04844448888") returns true (all characters are digits), but NumberUtils.createNumber("04844448888") follows Java number literal conventions where leading 0 means octal. SQL test parameters should always use decimal interpretation — SQL has no octal number syntax.

Fix

Replaced NumberUtils.createNumber() with Integer.valueOf() / Long.valueOf() which always parse as decimal:

  • Try Integer.valueOf() first (preserves existing Integer return type for small values)
  • Fall back to Long.valueOf() for values exceeding Integer range
  • Fall back to returning the original string if both overflow

Removed the unused NumberUtils import.

Tests Added

Change Point Test
Regular integer parsed as decimal Integer assertCreateInputParameterWithRegularInteger"1"Integer(1)
Large integer within int range assertCreateInputParameterWithLargeNumber"1000"Integer(1000)
Leading-zero string that was crashing (octal with invalid digits) assertCreateInputParameterWithLeadingZeroDigits"04844448888"Long(4844448888)
Leading-zero string that was silently mis-parsed as octal assertCreateInputParameterWithLeadingZeroValidOctalLikeDigits"04100001111"Long(4100001111)
Single zero assertCreateInputParameterWithSingleZero"0"Integer(0)
Non-numeric string assertCreateInputParameterWithString"aaa"String("aaa")
NULL literal assertCreateInputParameterWithNull"NULL"null
Long overflow fallback assertCreateInputParameterWithLongOverflow — returns String

Impact

Only affects the SQL rewrite test parameter builder. No runtime code changes. All existing test parameters (which have no leading-zero numeric values) produce identical results.

Fixes #31001

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQL-rewrite-test phone number createInputParameter error

1 participant