8146484: Examine sun.misc.MessageUtils

Reviewed-by: alanb, mchung, sherman
This commit is contained in:
Chris Hegarty 2016-01-06 17:40:48 +00:00
parent 41477d597a
commit 0c7d3be7a8
7 changed files with 21 additions and 159 deletions

View File

@ -216,6 +216,7 @@ SUNWprivate_1.1 {
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 @@ SUNWprivate_1.1 {
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;

View File

@ -35,8 +35,6 @@ import java.util.Hashtable;
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.

View File

@ -39,7 +39,6 @@ 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;
@ -106,11 +105,11 @@ class StringCoding {
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 @@ class StringCoding {
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 @@ class StringCoding {
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);
}

View File

@ -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");
}
}

View File

@ -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 @@ printToFile(JNIEnv *env, jstring s, FILE *file)
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 @@ printToFile(JNIEnv *env, jstring s, FILE *file)
}
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);
}

View File

@ -35,8 +35,6 @@ import java.util.Vector;
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

View File

@ -44,7 +44,6 @@ import sun.awt.AppContext;
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 @@ abstract class AppletPanel extends Panel implements AppletStub, Runnable {
*/
Dimension currentAppletSize = new Dimension(10, 10);
MessageUtils mu = new MessageUtils();
/**
* The thread to use during applet loading
*/