-
Bug
-
Resolution: Fixed
-
P4
-
8-pool, 9
-
b77
-
x86
-
os_x
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8136077 | emb-9 | Xueming Shen | P4 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
The documentation of java.util.Formatter states the following about the %n converter:
Line Separator
The conversion does not correspond to any argument.
'n' the platform-specific line separator as returned by System.getProperty("line.separator").
This is incorrect. It uses `System.lineSeparator()`, which reflects only the *initial* value of the "line.separator" property. Changing the property in runtime does not affect the behavior of the "%n" conversion. (Compare to the behavior of java.nio.file.Files.write(), which is affected by runtime changes in "line.separator").
The documentation of java.util.Formatter should be changed to match the code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case program on a machine whose line separator is LF (Mac, Linux):
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output:
[10]
[13, 10]
[13, 10]
ACTUAL -
Output:
[10]
[13, 10]
[10]
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Formatter;
public class SimpleTest {
public static void main(String[] args) {
System.out.println(Arrays.toString(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8)));
System.setProperty("line.separator", "\r\n");
System.out.println(Arrays.toString(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8)));
Formatter f = new Formatter();
f.format("%n");
System.out.println(Arrays.toString(f.out().toString().getBytes(StandardCharsets.UTF_8)));
}
}
---------- END SOURCE ----------
A DESCRIPTION OF THE PROBLEM :
The documentation of java.util.Formatter states the following about the %n converter:
Line Separator
The conversion does not correspond to any argument.
'n' the platform-specific line separator as returned by System.getProperty("line.separator").
This is incorrect. It uses `System.lineSeparator()`, which reflects only the *initial* value of the "line.separator" property. Changing the property in runtime does not affect the behavior of the "%n" conversion. (Compare to the behavior of java.nio.file.Files.write(), which is affected by runtime changes in "line.separator").
The documentation of java.util.Formatter should be changed to match the code.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the test case program on a machine whose line separator is LF (Mac, Linux):
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Output:
[10]
[13, 10]
[13, 10]
ACTUAL -
Output:
[10]
[13, 10]
[10]
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Formatter;
public class SimpleTest {
public static void main(String[] args) {
System.out.println(Arrays.toString(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8)));
System.setProperty("line.separator", "\r\n");
System.out.println(Arrays.toString(System.getProperty("line.separator").getBytes(StandardCharsets.UTF_8)));
Formatter f = new Formatter();
f.format("%n");
System.out.println(Arrays.toString(f.out().toString().getBytes(StandardCharsets.UTF_8)));
}
}
---------- END SOURCE ----------
- backported by
-
JDK-8136077 java.util.Formatter documentation of %n converter is misleading
-
- Resolved
-