8146484: Examine sun.misc.MessageUtils
Reviewed-by: alanb, mchung, sherman
diff --git a/jdk/make/mapfiles/libjava/mapfile-vers b/jdk/make/mapfiles/libjava/mapfile-vers
index ac1be88..3ec9f53 100644
--- a/jdk/make/mapfiles/libjava/mapfile-vers
+++ b/jdk/make/mapfiles/libjava/mapfile-vers
@@ -216,6 +216,7 @@
Java_java_lang_SecurityManager_getClassContext;
Java_java_lang_Shutdown_halt0;
Java_java_lang_String_intern;
+ Java_java_lang_StringCoding_err;
Java_java_lang_StringUTF16_isBigEndian;
Java_java_lang_System_identityHashCode;
Java_java_lang_System_initProperties;
@@ -243,8 +244,6 @@
Java_java_util_TimeZone_getSystemTimeZoneID;
Java_java_util_TimeZone_getSystemGMTOffsetID;
Java_java_util_concurrent_atomic_AtomicLong_VMSupportsCS8;
- Java_sun_misc_MessageUtils_toStderr;
- Java_sun_misc_MessageUtils_toStdout;
Java_sun_misc_NativeSignalHandler_handle0;
Java_sun_misc_Signal_findSignal;
Java_sun_misc_Signal_handle0;
diff --git a/jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java b/jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java
index 753007a..0dee68e 100644
--- a/jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java
+++ b/jdk/make/src/classes/build/tools/dtdbuilder/DTDParser.java
@@ -35,8 +35,6 @@
import java.util.BitSet;
import java.text.MessageFormat;
-import sun.misc.MessageUtils;
-
/**
* A parser for DTDs. This parser roughly corresponds to the
* rules specified in "The SGML Handbook" by Charles F. Goldfarb.
diff --git a/jdk/src/java.base/share/classes/java/lang/StringCoding.java b/jdk/src/java.base/share/classes/java/lang/StringCoding.java
index b1e25d5..fe87537 100644
--- a/jdk/src/java.base/share/classes/java/lang/StringCoding.java
+++ b/jdk/src/java.base/share/classes/java/lang/StringCoding.java
@@ -39,7 +39,6 @@
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;
@@ -106,11 +105,11 @@
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;
}
}
@@ -341,10 +340,9 @@
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);
@@ -653,14 +651,20 @@
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);
}
diff --git a/jdk/src/java.base/share/classes/sun/misc/MessageUtils.java b/jdk/src/java.base/share/classes/sun/misc/MessageUtils.java
deleted file mode 100644
index 75d5ee4..0000000
--- a/jdk/src/java.base/share/classes/sun/misc/MessageUtils.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-package sun.misc;
-
-/**
- * MessageUtils: miscellaneous utilities for handling error and status
- * properties and messages.
- *
- * @author Herb Jellinek
- */
-
-public class MessageUtils {
- // can instantiate it for to allow less verbose use - via instance
- // instead of classname
-
- public MessageUtils() { }
-
- public static String subst(String patt, String arg) {
- String args[] = { arg };
- return subst(patt, args);
- }
-
- public static String subst(String patt, String arg1, String arg2) {
- String args[] = { arg1, arg2 };
- return subst(patt, args);
- }
-
- public static String subst(String patt, String arg1, String arg2,
- String arg3) {
- String args[] = { arg1, arg2, arg3 };
- return subst(patt, args);
- }
-
- public static String subst(String patt, String args[]) {
- StringBuilder result = new StringBuilder();
- int len = patt.length();
- for (int i = 0; i >= 0 && i < len; i++) {
- char ch = patt.charAt(i);
- if (ch == '%') {
- if (i != len) {
- int index = Character.digit(patt.charAt(i + 1), 10);
- if (index == -1) {
- result.append(patt.charAt(i + 1));
- i++;
- } else if (index < args.length) {
- result.append(args[index]);
- i++;
- }
- }
- } else {
- result.append(ch);
- }
- }
- return result.toString();
- }
-
- public static String substProp(String propName, String arg) {
- return subst(System.getProperty(propName), arg);
- }
-
- public static String substProp(String propName, String arg1, String arg2) {
- return subst(System.getProperty(propName), arg1, arg2);
- }
-
- public static String substProp(String propName, String arg1, String arg2,
- String arg3) {
- return subst(System.getProperty(propName), arg1, arg2, arg3);
- }
-
- /**
- * Print a message directly to stderr, bypassing all the
- * character conversion methods.
- * @param msg message to print
- */
- public static native void toStderr(String msg);
-
- /**
- * Print a message directly to stdout, bypassing all the
- * character conversion methods.
- * @param msg message to print
- */
- public static native void toStdout(String msg);
-
-
- // Short forms of the above
-
- public static void err(String s) {
- toStderr(s + "\n");
- }
-
- public static void out(String s) {
- toStdout(s + "\n");
- }
-
- // Print a stack trace to stderr
- //
- public static void where() {
- Throwable t = new Throwable();
- StackTraceElement[] es = t.getStackTrace();
- for (int i = 1; i < es.length; i++)
- toStderr("\t" + es[i].toString() + "\n");
- }
-
-}
diff --git a/jdk/src/java.base/share/native/libjava/MessageUtils.c b/jdk/src/java.base/share/native/libjava/StringCoding.c
similarity index 86%
rename from jdk/src/java.base/share/native/libjava/MessageUtils.c
rename to jdk/src/java.base/share/native/libjava/StringCoding.c
index 49315dc..9ca51cd 100644
--- a/jdk/src/java.base/share/native/libjava/MessageUtils.c
+++ b/jdk/src/java.base/share/native/libjava/StringCoding.c
@@ -26,11 +26,10 @@
#include <stdlib.h>
#include <jni.h>
#include <jni_util.h>
-#include <jlong.h>
#include <stdio.h>
#include <jvm.h>
-#include "sun_misc_MessageUtils.h"
+#include "java_lang_StringCoding.h"
static void
printToFile(JNIEnv *env, jstring s, FILE *file)
@@ -41,8 +40,8 @@
const jchar *sAsArray;
if (s == NULL) {
- s = (*env)->NewStringUTF(env, "null");
- if (s == NULL) return;
+ JNU_ThrowNullPointerException(env, NULL);
+ return;
}
sAsArray = (*env)->GetStringChars(env, s, NULL);
@@ -70,13 +69,7 @@
}
JNIEXPORT void JNICALL
-Java_sun_misc_MessageUtils_toStderr(JNIEnv *env, jclass cls, jstring s)
+Java_java_lang_StringCoding_err(JNIEnv *env, jclass cls, jstring s)
{
printToFile(env, s, stderr);
}
-
-JNIEXPORT void JNICALL
-Java_sun_misc_MessageUtils_toStdout(JNIEnv *env, jclass cls, jstring s)
-{
- printToFile(env, s, stdout);
-}
diff --git a/jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java b/jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java
index 5379d63..d178ae4 100644
--- a/jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java
+++ b/jdk/src/java.desktop/share/classes/javax/swing/text/html/parser/Parser.java
@@ -35,8 +35,6 @@
import java.util.Enumeration;
import java.net.URL;
-import sun.misc.MessageUtils;
-
/**
* A simple DTD-driven HTML parser. The parser reads an
* HTML file from an InputStream and calls various methods
diff --git a/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java b/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java
index a9bacd5..2283e2f 100644
--- a/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java
+++ b/jdk/src/java.desktop/share/classes/sun/applet/AppletPanel.java
@@ -44,7 +44,6 @@
import sun.awt.EmbeddedFrame;
import sun.awt.SunToolkit;
import sun.misc.ManagedLocalsThread;
-import sun.misc.MessageUtils;
import sun.misc.PerformanceLogger;
import sun.security.util.SecurityConstants;
@@ -118,8 +117,6 @@
*/
Dimension currentAppletSize = new Dimension(10, 10);
- MessageUtils mu = new MessageUtils();
-
/**
* The thread to use during applet loading
*/