diff --git a/jdk/src/share/classes/java/lang/System.java b/jdk/src/share/classes/java/lang/System.java index b0c46528cbd..3d55a2eaea4 100644 --- a/jdk/src/share/classes/java/lang/System.java +++ b/jdk/src/share/classes/java/lang/System.java @@ -619,6 +619,20 @@ public final class System { return props; } + /** + * Returns the system-dependent line separator string. It always + * returns the same value - the initial value of the {@linkplain + * #getProperty(String) system property} {@code line.separator}. + * + *
On UNIX systems, it returns {@code "\n"}; on Microsoft
+ * Windows systems it returns {@code "\r\n"}.
+ */
+ public static String lineSeparator() {
+ return lineSeparator;
+ }
+
+ private static String lineSeparator;
+
/**
* Sets the system properties to the Properties
* argument.
@@ -1104,6 +1118,7 @@ public final class System {
private static void initializeSystemClass() {
props = new Properties();
initProperties(props);
+ lineSeparator = props.getProperty("line.separator");
sun.misc.Version.init();
// Workaround until DownloadManager initialization is revisited.
@@ -1192,7 +1207,7 @@ public final class System {
}
/* returns the class of the caller. */
- static Class getCallerClass() {
+ static Class> getCallerClass() {
// NOTE use of more generic Reflection.getCallerClass()
return Reflection.getCallerClass(3);
}
diff --git a/jdk/src/share/classes/java/util/Formatter.java b/jdk/src/share/classes/java/util/Formatter.java
index 59ff1da0711..46a6431298c 100644
--- a/jdk/src/share/classes/java/util/Formatter.java
+++ b/jdk/src/share/classes/java/util/Formatter.java
@@ -2552,9 +2552,6 @@ public final class Formatter implements Closeable, Flushable {
private boolean dt = false;
private char c;
- // cache the line separator
- private String ls;
-
private int index(String s) {
if (s != null) {
try {
@@ -2702,9 +2699,7 @@ public final class Formatter implements Closeable, Flushable {
printHashCode(arg);
break;
case Conversion.LINE_SEPARATOR:
- if (ls == null)
- ls = System.getProperty("line.separator");
- a.append(ls);
+ a.append(System.lineSeparator());
break;
case Conversion.PERCENT_SIGN:
a.append('%');