makssent opened a new issue, #38805:
URL: https://github.com/apache/shardingsphere/issues/38805
## Bug Report
### Which version of ShardingSphere did you use?
master (also affects released versions, the code has been present since
5.x).
### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
Both (the algorithm lives in `shardingsphere-sharding-core`).
### Expected behavior
`AutoIntervalShardingAlgorithm` should compute the target table suffix
correctly regardless of the JVM's default locale.
### Actual behavior
When the JVM default locale uses a comma as the decimal separator
(e.g. `ru_RU`, `de_DE`, `fr_FR`), sharding fails with:
java.lang.NumberFormatException: For input string: "11,00"
at java.lang.Double.parseDouble(Double.java:971)
at
org.apache.shardingsphere.sharding.algorithm.sharding.datetime.AutoIntervalShardingAlgorithm.doSharding(AutoIntervalShardingAlgorithm.java:103)
### Reason analyze (If you can)
In
`features/sharding/core/src/main/java/org/apache/shardingsphere/sharding/algorithm/sharding/datetime/AutoIntervalShardingAlgorithm.java`,
method `doSharding(long)`:
```java
String position = new DecimalFormat("0.00").format((double) shardingValue
/ shardingSeconds);
return Math.min(Math.max(0, (int)
Math.ceil(Double.parseDouble(position))), autoTablesAmount - 1);
new DecimalFormat("0.00") uses the JVM default locale's
DecimalFormatSymbols. On comma-decimal locales it formats the value as
e.g. "11,00", which the subsequent Double.parseDouble(...) cannot
parse, throwing NumberFormatException. The format/parse round-trip must
be locale-independent (Locale.ROOT).
Steps to reproduce the behavior
1. Set the JVM default locale to one using a comma decimal separator,
e.g. run with -Duser.language=ru -Duser.country=RU.
2. Configure an AUTO_INTERVAL sharding algorithm and execute a query
that triggers sharding.
3. Observe the NumberFormatException.
This is also reproducible by running AutoIntervalShardingAlgorithmTest
under such a locale — 8 of 10 tests fail with the exception above.
Example codes for reproduce this issue (such as a github link).
AutoIntervalShardingAlgorithmTest in shardingsphere-sharding-core
reproduces it directly when the default locale uses a comma separator.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail:
[email protected]
For queries about this service, please contact Infrastructure at:
[email protected]