src/java.base/share/classes/java/lang/StringCoding.java
Print this page
@@ -37,11 +37,10 @@
import java.nio.charset.CodingErrorAction;
import java.nio.charset.IllegalCharsetNameException;
import java.nio.charset.UnsupportedCharsetException;
import java.util.Arrays;
import jdk.internal.HotSpotIntrinsicCandidate;
-import sun.misc.MessageUtils;
import sun.nio.cs.HistoricallyNamedCharset;
import sun.nio.cs.ArrayDecoder;
import sun.nio.cs.ArrayEncoder;
import static java.lang.String.LATIN1;
@@ -104,15 +103,15 @@
return null;
}
private static void warnUnsupportedCharset(String csn) {
if (warnUnsupportedCharset) {
- // Use sun.misc.MessageUtils rather than the Logging API or
- // System.err since this method may be called during VM
- // initialization before either is available.
- MessageUtils.err("WARNING: Default charset " + csn +
- " not supported, using ISO-8859-1 instead");
+ // Use err(String) rather than the Logging API or System.err
+ // since this method may be called during VM initialization
+ // before either is available.
+ err("WARNING: Default charset " + csn +
+ " not supported, using ISO-8859-1 instead\n");
warnUnsupportedCharset = false;
}
}
static class Result {
@@ -339,14 +338,13 @@
warnUnsupportedCharset(csn);
}
try {
return decode("ISO-8859-1", ba, off, len);
} catch (UnsupportedEncodingException x) {
- // If this code is hit during VM initialization, MessageUtils is
+ // If this code is hit during VM initialization, err(String) is
// the only way we will be able to get any kind of error message.
- MessageUtils.err("ISO-8859-1 charset not available: "
- + x.toString());
+ err("ISO-8859-1 charset not available: " + x.toString() + "\n");
// If we can not find ISO-8859-1 (a required encoding) then things
// are seriously wrong with the installation.
System.exit(1);
return null;
}
@@ -651,16 +649,22 @@
warnUnsupportedCharset(csn);
}
try {
return encode("ISO-8859-1", coder, val);
} catch (UnsupportedEncodingException x) {
- // If this code is hit during VM initialization, MessageUtils is
+ // If this code is hit during VM initialization, err(String) is
// the only way we will be able to get any kind of error message.
- MessageUtils.err("ISO-8859-1 charset not available: "
- + x.toString());
+ err("ISO-8859-1 charset not available: " + x.toString() + "\n");
// If we can not find ISO-8859-1 (a required encoding) then things
// are seriously wrong with the installation.
System.exit(1);
return null;
}
}
+
+ /**
+ * Print a message directly to stderr, bypassing all character conversion
+ * methods.
+ * @param msg message to print
+ */
+ private static native void err(String msg);
}