Fix test parameter parsing treating leading-zero strings as octal#38569
Open
daguimu wants to merge 1 commit intoapache:masterfrom
Open
Fix test parameter parsing treating leading-zero strings as octal#38569daguimu wants to merge 1 commit intoapache:masterfrom
daguimu wants to merge 1 commit intoapache:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
SQLRewriteEngineTestParametersBuilder.createInputParameter()usesNumberUtils.createNumber()to parse test parameter strings. When a parameter string consists entirely of digits but starts with '0' (e.g., encrypted phone number04844448888),NumberUtils.createNumber()interprets it as an octal literal per Java conventions, throwingNumberFormatExceptionsince 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")returnstrue(all characters are digits), butNumberUtils.createNumber("04844448888")follows Java number literal conventions where leading0means octal. SQL test parameters should always use decimal interpretation — SQL has no octal number syntax.Fix
Replaced
NumberUtils.createNumber()withInteger.valueOf()/Long.valueOf()which always parse as decimal:Integer.valueOf()first (preserves existing Integer return type for small values)Long.valueOf()for values exceeding Integer rangeRemoved the unused
NumberUtilsimport.Tests Added
assertCreateInputParameterWithRegularInteger—"1"→Integer(1)assertCreateInputParameterWithLargeNumber—"1000"→Integer(1000)assertCreateInputParameterWithLeadingZeroDigits—"04844448888"→Long(4844448888)assertCreateInputParameterWithLeadingZeroValidOctalLikeDigits—"04100001111"→Long(4100001111)assertCreateInputParameterWithSingleZero—"0"→Integer(0)assertCreateInputParameterWithString—"aaa"→String("aaa")assertCreateInputParameterWithNull—"NULL"→nullassertCreateInputParameterWithLongOverflow— returns StringImpact
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