-
Bug
-
Resolution: Fixed
-
P4
-
8, 11, 17, 19, 20
-
b06
-
generic
-
generic
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8315858 | 17.0.10 | Paul Hohensee | P4 | Resolved | Fixed | b01 |
JDK-8329716 | 11.0.24 | Paul Hohensee | P4 | Resolved | Fixed | b01 |
JDK-8335924 | openjdk8u432 | Paul Hohensee | P4 | Resolved | Fixed | b01 |
Any OS (tested on Ubuntu, and MacOS) and also tested on JDK8 and JDK17
A DESCRIPTION OF THE PROBLEM :
String.format takes tens of minutes to format a floating point if format specifies that it should be prepended with large number of 0. e.g. String.format("%09000000d", 2);
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The code below took 1693 seconds (28 minutes) to return a string with 9 millions of chars. Same happens for 'f' format specifier. Time spent in format seems to increase quadric with the width of the generated string.
String s = String.format("%09000000d", 2);
However, the code below, that use 'x' as specifier returns way faster
String s = String.format("%09000000x", 2);
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the String.format to take similar amount of time regardless of formatter.
ACTUAL -
Returns correct result but very slow for 'd' and 'f' format specifier. Works as expected on for 'x' format specifier
---------- BEGIN SOURCE ----------
public class SystemFormat {
public static void main(String[] args) {
long t1 = System.currentTimeMillis();
String sd = String.format("%0500000d", 2);
long t2 = System.currentTimeMillis();
String sx = String.format("%0500000x", 2);
long t3 = System.currentTimeMillis();
long diff1 = t2 - t1;
long diff2 = t3 - t2;
System.out.format("diff1 = %d%n", diff1);
System.out.format("diff2 = %d%n", diff2);
}
}
// outputs
// diff1 = 5927
// diff2 = 10
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
do not use String.format with larger specifier and prepend it with '0'.
FREQUENCY : always
- backported by
-
JDK-8315858 Formatter.format might take a long time to format an integer or floating-point
- Resolved
-
JDK-8329716 Formatter.format might take a long time to format an integer or floating-point
- Resolved
-
JDK-8335924 Formatter.format might take a long time to format an integer or floating-point
- Resolved
- relates to
-
JDK-8313307 java/util/Formatter/Padding.java fails on some Locales
- Resolved
-
JDK-8326718 Test java/util/Formatter/Padding.java should timeout on large inputs before fix in JDK-8299677
- Resolved
- links to
-
Commit openjdk/jdk8u-dev/ddce2b5d
-
Commit openjdk/jdk11u-dev/9ac4063d
-
Commit openjdk/jdk17u-dev/6b192d3b
-
Commit openjdk/jdk/33412c10
-
Review openjdk/jdk11u-dev/1667
-
Review openjdk/jdk17u-dev/1077
-
Review openjdk/jdk/11939
-
Review(master) openjdk/jdk8u-dev/459