Update (2025-08-31): Clarify the scope and implementation plan.
- We will keep the original method isNumeric(String, boolean)
behavior unchanged (signed inputs still fail).
- Add a new overload: isNumeric(String str, boolean allowDot, boolean allowSign)
.
- The old method will delegate to the new one with allowSign = false
.
- Unit tests will include regression checks for the old method and new tests for signed numbers.
Pre-check
- [x] I am sure that all the content I provide is in English.
Search before asking
- [x] I had searched in the issues and found no similar feature requirement.
Apache Dubbo Component
Java SDK (apache/dubbo)
Descriptions
Summary
Add an overload StringUtils.isNumeric(String str, boolean allowDot, boolean allowSign)
to optionally allow a single leading +
or -
while keeping the existing API and behavior unchanged.
Motivation
Some call sites need to accept signed integers/decimals (e.g., -1
, +1.23
). The current isNumeric(String, boolean allowDot)
rejects any leading sign, which leads to ad-hoc checks or rejecting valid inputs. Centralizing this logic in StringUtils
reduces duplication and avoids subtle bugs.
Proposed change
- Introduce
isNumeric(String, boolean allowDot, boolean allowSign)
. - When
allowSign == true
, accept exactly one leading sign at index 0. - A lone sign (
"+"
or"-"
) remains invalid. - Dot rule unchanged: at most one dot if
allowDot == true
; otherwise any dot fails. - Whitespace is not trimmed: any whitespace causes
false
. - Only ASCII digits are recognized; no scientific notation or locale digits.
Non-goals
- Do not change the semantics of the existing
isNumeric(String, boolean)
. - Do not support scientific notation (
1e3
) or locale-specific numerals. - Do not add parsing/normalization (e.g., no trimming or
BigDecimal
parsing).
Compatibility
- Strictly backward compatible: the original method and its semantics remain intact; existing callers observe no behavior change.
Affected component
- Module:
dubbo-common
- Class:
org.apache.dubbo.common.utils.StringUtils
Test plan / Acceptance criteria
Add unit tests covering:
- Signed and unsigned integers/decimals:
- "-1"
→ pass only when allowSign == true
- "+1.23"
→ pass only when allowDot && allowSign
- Lone sign: "+"
, "-"
→ always false
- Multiple dots: "1.2.3"
→ false
- Non-digit characters: "12a"
, "--1"
, "+-1"
→ false
- Whitespace: " 1"
, "1 "
→ false
- Null / empty: null
, ""
→ false
- Regression: the original method still returns false for "-1"
/ "+1.23"
CI note
Run mvn -q -pl dubbo-common -am test
in a networked environment so the parent POM and dependencies can be resolved.
Related issues
None found after searching for “StringUtils.isNumeric” / “allow sign” / “signed number”. This issue will be referenced by the upcoming PR.
Are you willing to submit a pull request to fix on your own?
- [x] Yes I am willing to submit a pull request on my own!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct