提交 819755bd 编写于 作者: C chegar

7116722: Miscellaneous warnings sun.misc ( and related classes )

Reviewed-by: alanb, darcy, forax, hawtin, lancea
上级 7756546b
...@@ -31,7 +31,7 @@ import java.net.*; ...@@ -31,7 +31,7 @@ import java.net.*;
import java.security.AccessController; import java.security.AccessController;
import java.security.PrivilegedAction; import java.security.PrivilegedAction;
import java.util.Iterator; import java.util.Iterator;
import sun.misc.Service; import java.util.ServiceLoader;
import sun.misc.ServiceConfigurationError; import sun.misc.ServiceConfigurationError;
import sun.security.action.GetPropertyAction; import sun.security.action.GetPropertyAction;
import com.sun.net.httpserver.*; import com.sun.net.httpserver.*;
...@@ -94,9 +94,10 @@ public abstract class HttpServerProvider { ...@@ -94,9 +94,10 @@ public abstract class HttpServerProvider {
} }
private static boolean loadProviderAsService() { private static boolean loadProviderAsService() {
@SuppressWarnings("unchecked") Iterator<HttpServerProvider> i =
Iterator<HttpServerProvider> i = Service.providers(HttpServerProvider.class, ServiceLoader.load(HttpServerProvider.class,
ClassLoader.getSystemClassLoader()); ClassLoader.getSystemClassLoader())
.iterator();
for (;;) { for (;;) {
try { try {
if (!i.hasNext()) if (!i.hasNext())
......
...@@ -32,6 +32,7 @@ import java.util.Iterator; ...@@ -32,6 +32,7 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.ServiceLoader;
import java.security.AccessController; import java.security.AccessController;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.IOException; import java.io.IOException;
...@@ -39,7 +40,6 @@ import java.io.ObjectInputStream; ...@@ -39,7 +40,6 @@ import java.io.ObjectInputStream;
import sun.security.action.*; import sun.security.action.*;
import sun.net.InetAddressCachePolicy; import sun.net.InetAddressCachePolicy;
import sun.net.util.IPAddressUtil; import sun.net.util.IPAddressUtil;
import sun.misc.Service;
import sun.net.spi.nameservice.*; import sun.net.spi.nameservice.*;
/** /**
...@@ -876,10 +876,9 @@ class InetAddress implements java.io.Serializable { ...@@ -876,10 +876,9 @@ class InetAddress implements java.io.Serializable {
nameService = java.security.AccessController.doPrivileged( nameService = java.security.AccessController.doPrivileged(
new java.security.PrivilegedExceptionAction<NameService>() { new java.security.PrivilegedExceptionAction<NameService>() {
public NameService run() { public NameService run() {
// sun.misc.Service.providers returns a raw Iterator
@SuppressWarnings("unchecked")
Iterator<NameServiceDescriptor> itr = Iterator<NameServiceDescriptor> itr =
Service.providers(NameServiceDescriptor.class); ServiceLoader.load(NameServiceDescriptor.class)
.iterator();
while (itr.hasNext()) { while (itr.hasNext()) {
NameServiceDescriptor nsd = itr.next(); NameServiceDescriptor nsd = itr.next();
if (providerName. if (providerName.
......
...@@ -90,7 +90,7 @@ class JarVerifier { ...@@ -90,7 +90,7 @@ class JarVerifier {
private Object csdomain = new Object(); private Object csdomain = new Object();
/** collect -DIGEST-MANIFEST values for blacklist */ /** collect -DIGEST-MANIFEST values for blacklist */
private List manifestDigests; private List<Object> manifestDigests;
public JarVerifier(byte rawBytes[]) { public JarVerifier(byte rawBytes[]) {
manifestRawBytes = rawBytes; manifestRawBytes = rawBytes;
...@@ -99,7 +99,7 @@ class JarVerifier { ...@@ -99,7 +99,7 @@ class JarVerifier {
sigFileData = new Hashtable(11); sigFileData = new Hashtable(11);
pendingBlocks = new ArrayList(); pendingBlocks = new ArrayList();
baos = new ByteArrayOutputStream(); baos = new ByteArrayOutputStream();
manifestDigests = new ArrayList(); manifestDigests = new ArrayList<>();
} }
/** /**
...@@ -872,7 +872,7 @@ class JarVerifier { ...@@ -872,7 +872,7 @@ class JarVerifier {
eagerValidation = eager; eagerValidation = eager;
} }
public synchronized List getManifestDigests() { public synchronized List<Object> getManifestDigests() {
return Collections.unmodifiableList(manifestDigests); return Collections.unmodifiableList(manifestDigests);
} }
......
...@@ -57,7 +57,7 @@ class JavaUtilJarAccessImpl implements JavaUtilJarAccess { ...@@ -57,7 +57,7 @@ class JavaUtilJarAccessImpl implements JavaUtilJarAccess {
jar.setEagerValidation(eager); jar.setEagerValidation(eager);
} }
public List getManifestDigests(JarFile jar) { public List<Object> getManifestDigests(JarFile jar) {
return jar.getManifestDigests(); return jar.getManifestDigests();
} }
} }
...@@ -102,7 +102,7 @@ public class ScriptEngineManager { ...@@ -102,7 +102,7 @@ public class ScriptEngineManager {
} }
private void initEngines(final ClassLoader loader) { private void initEngines(final ClassLoader loader) {
Iterator itr = null; Iterator<ScriptEngineFactory> itr = null;
try { try {
if (loader != null) { if (loader != null) {
itr = Service.providers(ScriptEngineFactory.class, loader); itr = Service.providers(ScriptEngineFactory.class, loader);
...@@ -124,7 +124,7 @@ public class ScriptEngineManager { ...@@ -124,7 +124,7 @@ public class ScriptEngineManager {
try { try {
while (itr.hasNext()) { while (itr.hasNext()) {
try { try {
ScriptEngineFactory fact = (ScriptEngineFactory) itr.next(); ScriptEngineFactory fact = itr.next();
engineSpis.add(fact); engineSpis.add(fact);
} catch (ServiceConfigurationError err) { } catch (ServiceConfigurationError err) {
System.err.println("ScriptEngineManager providers.next(): " System.err.println("ScriptEngineManager providers.next(): "
...@@ -441,7 +441,7 @@ public class ScriptEngineManager { ...@@ -441,7 +441,7 @@ public class ScriptEngineManager {
// Note that this code is same as ClassLoader.getCallerClassLoader(). // Note that this code is same as ClassLoader.getCallerClassLoader().
// But, that method is package private and hence we can't call here. // But, that method is package private and hence we can't call here.
private ClassLoader getCallerClassLoader() { private ClassLoader getCallerClassLoader() {
Class caller = Reflection.getCallerClass(3); Class<?> caller = Reflection.getCallerClass(3);
if (caller == null) { if (caller == null) {
return null; return null;
} }
......
...@@ -102,6 +102,7 @@ public class BASE64Decoder extends CharacterDecoder { ...@@ -102,6 +102,7 @@ public class BASE64Decoder extends CharacterDecoder {
/** /**
* Decode one BASE64 atom into 1, 2, or 3 bytes of data. * Decode one BASE64 atom into 1, 2, or 3 bytes of data.
*/ */
@SuppressWarnings("fallthrough")
protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem) protected void decodeAtom(PushbackInputStream inStream, OutputStream outStream, int rem)
throws java.io.IOException throws java.io.IOException
{ {
......
...@@ -70,7 +70,7 @@ import sun.net.www.ParseUtil; ...@@ -70,7 +70,7 @@ import sun.net.www.ParseUtil;
public class ExtensionDependency { public class ExtensionDependency {
/* Callbak interfaces to delegate installation of missing extensions */ /* Callbak interfaces to delegate installation of missing extensions */
private static Vector providers; private static Vector<ExtensionInstallationProvider> providers;
/** /**
* <p> * <p>
...@@ -83,7 +83,7 @@ public class ExtensionDependency { ...@@ -83,7 +83,7 @@ public class ExtensionDependency {
(ExtensionInstallationProvider eip) (ExtensionInstallationProvider eip)
{ {
if (providers == null) { if (providers == null) {
providers = new Vector(); providers = new Vector<>();
} }
providers.add(eip); providers.add(eip);
} }
...@@ -93,7 +93,7 @@ public class ExtensionDependency { ...@@ -93,7 +93,7 @@ public class ExtensionDependency {
* Unregister a previously installed installation provider * Unregister a previously installed installation provider
* </p> * </p>
*/ */
public synchronized static void removeExtensionInstallationProvider public synchronized static void removeExtensionInstallationProvider
(ExtensionInstallationProvider eip) (ExtensionInstallationProvider eip)
{ {
providers.remove(eip); providers.remove(eip);
...@@ -348,14 +348,16 @@ public class ExtensionDependency { ...@@ -348,14 +348,16 @@ public class ExtensionDependency {
ExtensionInfo instInfo) ExtensionInfo instInfo)
throws ExtensionInstallationException throws ExtensionInstallationException
{ {
Vector<ExtensionInstallationProvider> currentProviders;
Vector currentProviders;
synchronized(providers) { synchronized(providers) {
currentProviders = (Vector) providers.clone(); @SuppressWarnings("unchecked")
Vector<ExtensionInstallationProvider> tmp =
(Vector<ExtensionInstallationProvider>) providers.clone();
currentProviders = tmp;
} }
for (Enumeration e=currentProviders.elements();e.hasMoreElements();) { for (Enumeration<ExtensionInstallationProvider> e = currentProviders.elements();
ExtensionInstallationProvider eip = e.hasMoreElements();) {
(ExtensionInstallationProvider) e.nextElement(); ExtensionInstallationProvider eip = e.nextElement();
if (eip!=null) { if (eip!=null) {
// delegate the installation to the provider // delegate the installation to the provider
......
...@@ -48,13 +48,13 @@ public class JarIndex { ...@@ -48,13 +48,13 @@ public class JarIndex {
* The hash map that maintains mappings from * The hash map that maintains mappings from
* package/classe/resource to jar file list(s) * package/classe/resource to jar file list(s)
*/ */
private HashMap indexMap; private HashMap<String,LinkedList<String>> indexMap;
/** /**
* The hash map that maintains mappings from * The hash map that maintains mappings from
* jar file to package/class/resource lists * jar file to package/class/resource lists
*/ */
private HashMap jarMap; private HashMap<String,LinkedList<String>> jarMap;
/* /*
* An ordered list of jar file names. * An ordered list of jar file names.
...@@ -78,8 +78,8 @@ public class JarIndex { ...@@ -78,8 +78,8 @@ public class JarIndex {
* Constructs a new, empty jar index. * Constructs a new, empty jar index.
*/ */
public JarIndex() { public JarIndex() {
indexMap = new HashMap(); indexMap = new HashMap<>();
jarMap = new HashMap(); jarMap = new HashMap<>();
} }
/** /**
...@@ -150,10 +150,11 @@ public class JarIndex { ...@@ -150,10 +150,11 @@ public class JarIndex {
* Add the key, value pair to the hashmap, the value will * Add the key, value pair to the hashmap, the value will
* be put in a linked list which is created if necessary. * be put in a linked list which is created if necessary.
*/ */
private void addToList(String key, String value, HashMap t) { private void addToList(String key, String value,
LinkedList list = (LinkedList)t.get(key); HashMap<String,LinkedList<String>> t) {
LinkedList<String> list = t.get(key);
if (list == null) { if (list == null) {
list = new LinkedList(); list = new LinkedList<>();
list.add(value); list.add(value);
t.put(key, list); t.put(key, list);
} else if (!list.contains(value)) { } else if (!list.contains(value)) {
...@@ -166,13 +167,13 @@ public class JarIndex { ...@@ -166,13 +167,13 @@ public class JarIndex {
* *
* @param fileName the key of the mapping * @param fileName the key of the mapping
*/ */
public LinkedList get(String fileName) { public LinkedList<String> get(String fileName) {
LinkedList jarFiles = null; LinkedList<String> jarFiles = null;
if ((jarFiles = (LinkedList)indexMap.get(fileName)) == null) { if ((jarFiles = indexMap.get(fileName)) == null) {
/* try the package name again */ /* try the package name again */
int pos; int pos;
if((pos = fileName.lastIndexOf("/")) != -1) { if((pos = fileName.lastIndexOf("/")) != -1) {
jarFiles = (LinkedList)indexMap.get(fileName.substring(0, pos)); jarFiles = indexMap.get(fileName.substring(0, pos));
} }
} }
return jarFiles; return jarFiles;
...@@ -235,9 +236,9 @@ public class JarIndex { ...@@ -235,9 +236,9 @@ public class JarIndex {
ZipFile zrf = new ZipFile(currentJar.replace ZipFile zrf = new ZipFile(currentJar.replace
('/', File.separatorChar)); ('/', File.separatorChar));
Enumeration entries = zrf.entries(); Enumeration<? extends ZipEntry> entries = zrf.entries();
while(entries.hasMoreElements()) { while(entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement(); ZipEntry entry = entries.nextElement();
String fileName = entry.getName(); String fileName = entry.getName();
// Skip the META-INF directory, the index, and manifest. // Skip the META-INF directory, the index, and manifest.
...@@ -282,11 +283,11 @@ public class JarIndex { ...@@ -282,11 +283,11 @@ public class JarIndex {
/* print out the jar file name */ /* print out the jar file name */
String jar = jarFiles[i]; String jar = jarFiles[i];
bw.write(jar + "\n"); bw.write(jar + "\n");
LinkedList jarlist = (LinkedList)jarMap.get(jar); LinkedList<String> jarlist = jarMap.get(jar);
if (jarlist != null) { if (jarlist != null) {
Iterator listitr = jarlist.iterator(); Iterator<String> listitr = jarlist.iterator();
while(listitr.hasNext()) { while(listitr.hasNext()) {
bw.write((String)(listitr.next()) + "\n"); bw.write(listitr.next() + "\n");
} }
} }
bw.write("\n"); bw.write("\n");
...@@ -309,7 +310,7 @@ public class JarIndex { ...@@ -309,7 +310,7 @@ public class JarIndex {
String currentJar = null; String currentJar = null;
/* an ordered list of jar file names */ /* an ordered list of jar file names */
Vector jars = new Vector(); Vector<String> jars = new Vector<>();
/* read until we see a .jar line */ /* read until we see a .jar line */
while((line = br.readLine()) != null && !line.endsWith(".jar")); while((line = br.readLine()) != null && !line.endsWith(".jar"));
...@@ -328,7 +329,7 @@ public class JarIndex { ...@@ -328,7 +329,7 @@ public class JarIndex {
} }
} }
jarFiles = (String[])jars.toArray(new String[jars.size()]); jarFiles = jars.toArray(new String[jars.size()]);
} }
/** /**
...@@ -342,14 +343,14 @@ public class JarIndex { ...@@ -342,14 +343,14 @@ public class JarIndex {
* *
*/ */
public void merge(JarIndex toIndex, String path) { public void merge(JarIndex toIndex, String path) {
Iterator itr = indexMap.entrySet().iterator(); Iterator<Map.Entry<String,LinkedList<String>>> itr = indexMap.entrySet().iterator();
while(itr.hasNext()) { while(itr.hasNext()) {
Map.Entry e = (Map.Entry)itr.next(); Map.Entry<String,LinkedList<String>> e = itr.next();
String packageName = (String)e.getKey(); String packageName = e.getKey();
LinkedList from_list = (LinkedList)e.getValue(); LinkedList<String> from_list = e.getValue();
Iterator listItr = from_list.iterator(); Iterator<String> listItr = from_list.iterator();
while(listItr.hasNext()) { while(listItr.hasNext()) {
String jarName = (String)listItr.next(); String jarName = listItr.next();
if (path != null) { if (path != null) {
jarName = path.concat(jarName); jarName = path.concat(jarName);
} }
......
...@@ -40,5 +40,5 @@ public interface JavaUtilJarAccess { ...@@ -40,5 +40,5 @@ public interface JavaUtilJarAccess {
public Enumeration<String> entryNames(JarFile jar, CodeSource[] cs); public Enumeration<String> entryNames(JarFile jar, CodeSource[] cs);
public Enumeration<JarEntry> entries2(JarFile jar); public Enumeration<JarEntry> entries2(JarFile jar);
public void setEagerValidation(JarFile jar, boolean eager); public void setEagerValidation(JarFile jar, boolean eager);
public List getManifestDigests(JarFile jar); public List<Object> getManifestDigests(JarFile jar);
} }
...@@ -351,7 +351,7 @@ public class ProxyGenerator { ...@@ -351,7 +351,7 @@ public class ProxyGenerator {
try { try {
hashCodeMethod = Object.class.getMethod("hashCode"); hashCodeMethod = Object.class.getMethod("hashCode");
equalsMethod = equalsMethod =
Object.class.getMethod("equals", new Class[] { Object.class }); Object.class.getMethod("equals", new Class<?>[] { Object.class });
toStringMethod = Object.class.getMethod("toString"); toStringMethod = Object.class.getMethod("toString");
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
throw new NoSuchMethodError(e.getMessage()); throw new NoSuchMethodError(e.getMessage());
...@@ -559,11 +559,11 @@ public class ProxyGenerator { ...@@ -559,11 +559,11 @@ public class ProxyGenerator {
* passed to the invocation handler's "invoke" method for a given * passed to the invocation handler's "invoke" method for a given
* set of duplicate methods. * set of duplicate methods.
*/ */
private void addProxyMethod(Method m, Class fromClass) { private void addProxyMethod(Method m, Class<?> fromClass) {
String name = m.getName(); String name = m.getName();
Class[] parameterTypes = m.getParameterTypes(); Class<?>[] parameterTypes = m.getParameterTypes();
Class returnType = m.getReturnType(); Class<?> returnType = m.getReturnType();
Class[] exceptionTypes = m.getExceptionTypes(); Class<?>[] exceptionTypes = m.getExceptionTypes();
String sig = name + getParameterDescriptors(parameterTypes); String sig = name + getParameterDescriptors(parameterTypes);
List<ProxyMethod> sigmethods = proxyMethods.get(sig); List<ProxyMethod> sigmethods = proxyMethods.get(sig);
...@@ -581,7 +581,7 @@ public class ProxyGenerator { ...@@ -581,7 +581,7 @@ public class ProxyGenerator {
exceptionTypes, pm.exceptionTypes, legalExceptions); exceptionTypes, pm.exceptionTypes, legalExceptions);
collectCompatibleTypes( collectCompatibleTypes(
pm.exceptionTypes, exceptionTypes, legalExceptions); pm.exceptionTypes, exceptionTypes, legalExceptions);
pm.exceptionTypes = new Class[legalExceptions.size()]; pm.exceptionTypes = new Class<?>[legalExceptions.size()];
pm.exceptionTypes = pm.exceptionTypes =
legalExceptions.toArray(pm.exceptionTypes); legalExceptions.toArray(pm.exceptionTypes);
return; return;
...@@ -848,15 +848,15 @@ public class ProxyGenerator { ...@@ -848,15 +848,15 @@ public class ProxyGenerator {
private class ProxyMethod { private class ProxyMethod {
public String methodName; public String methodName;
public Class[] parameterTypes; public Class<?>[] parameterTypes;
public Class returnType; public Class<?> returnType;
public Class[] exceptionTypes; public Class<?>[] exceptionTypes;
public Class fromClass; public Class<?> fromClass;
public String methodFieldName; public String methodFieldName;
private ProxyMethod(String methodName, Class[] parameterTypes, private ProxyMethod(String methodName, Class<?>[] parameterTypes,
Class returnType, Class[] exceptionTypes, Class<?> returnType, Class<?>[] exceptionTypes,
Class fromClass) Class<?> fromClass)
{ {
this.methodName = methodName; this.methodName = methodName;
this.parameterTypes = parameterTypes; this.parameterTypes = parameterTypes;
...@@ -1001,7 +1001,7 @@ public class ProxyGenerator { ...@@ -1001,7 +1001,7 @@ public class ProxyGenerator {
* invocation handler's "invoke" method. The code is written * invocation handler's "invoke" method. The code is written
* to the supplied stream. * to the supplied stream.
*/ */
private void codeWrapArgument(Class type, int slot, private void codeWrapArgument(Class<?> type, int slot,
DataOutputStream out) DataOutputStream out)
throws IOException throws IOException
{ {
...@@ -1042,7 +1042,7 @@ public class ProxyGenerator { ...@@ -1042,7 +1042,7 @@ public class ProxyGenerator {
* Object) to its correct type. The code is written to the * Object) to its correct type. The code is written to the
* supplied stream. * supplied stream.
*/ */
private void codeUnwrapReturnValue(Class type, DataOutputStream out) private void codeUnwrapReturnValue(Class<?> type, DataOutputStream out)
throws IOException throws IOException
{ {
if (type.isPrimitive()) { if (type.isPrimitive()) {
...@@ -1391,7 +1391,7 @@ public class ProxyGenerator { ...@@ -1391,7 +1391,7 @@ public class ProxyGenerator {
* the supplied stream. Note that the code generated by this method * the supplied stream. Note that the code generated by this method
* may caused the checked ClassNotFoundException to be thrown. * may caused the checked ClassNotFoundException to be thrown.
*/ */
private void codeClassForName(Class cl, DataOutputStream out) private void codeClassForName(Class<?> cl, DataOutputStream out)
throws IOException throws IOException
{ {
code_ldc(cp.getString(cl.getName()), out); code_ldc(cp.getString(cl.getName()), out);
...@@ -1422,8 +1422,8 @@ public class ProxyGenerator { ...@@ -1422,8 +1422,8 @@ public class ProxyGenerator {
* Return the "method descriptor" string for a method with the given * Return the "method descriptor" string for a method with the given
* parameter types and return type. See JVMS section 4.3.3. * parameter types and return type. See JVMS section 4.3.3.
*/ */
private static String getMethodDescriptor(Class[] parameterTypes, private static String getMethodDescriptor(Class<?>[] parameterTypes,
Class returnType) Class<?> returnType)
{ {
return getParameterDescriptors(parameterTypes) + return getParameterDescriptors(parameterTypes) +
((returnType == void.class) ? "V" : getFieldType(returnType)); ((returnType == void.class) ? "V" : getFieldType(returnType));
...@@ -1436,7 +1436,7 @@ public class ProxyGenerator { ...@@ -1436,7 +1436,7 @@ public class ProxyGenerator {
* string is useful for constructing string keys for methods without * string is useful for constructing string keys for methods without
* regard to their return type. * regard to their return type.
*/ */
private static String getParameterDescriptors(Class[] parameterTypes) { private static String getParameterDescriptors(Class<?>[] parameterTypes) {
StringBuilder desc = new StringBuilder("("); StringBuilder desc = new StringBuilder("(");
for (int i = 0; i < parameterTypes.length; i++) { for (int i = 0; i < parameterTypes.length; i++) {
desc.append(getFieldType(parameterTypes[i])); desc.append(getFieldType(parameterTypes[i]));
...@@ -1450,7 +1450,7 @@ public class ProxyGenerator { ...@@ -1450,7 +1450,7 @@ public class ProxyGenerator {
* a field descriptor, a parameter descriptor, or a return descriptor * a field descriptor, a parameter descriptor, or a return descriptor
* other than "void". See JVMS section 4.3.2. * other than "void". See JVMS section 4.3.2.
*/ */
private static String getFieldType(Class type) { private static String getFieldType(Class<?> type) {
if (type.isPrimitive()) { if (type.isPrimitive()) {
return PrimitiveTypeInfo.get(type).baseTypeString; return PrimitiveTypeInfo.get(type).baseTypeString;
} else if (type.isArray()) { } else if (type.isArray()) {
...@@ -1472,7 +1472,7 @@ public class ProxyGenerator { ...@@ -1472,7 +1472,7 @@ public class ProxyGenerator {
* method with the given name and parameter types. * method with the given name and parameter types.
*/ */
private static String getFriendlyMethodSignature(String name, private static String getFriendlyMethodSignature(String name,
Class[] parameterTypes) Class<?>[] parameterTypes)
{ {
StringBuilder sig = new StringBuilder(name); StringBuilder sig = new StringBuilder(name);
sig.append('('); sig.append('(');
...@@ -1480,7 +1480,7 @@ public class ProxyGenerator { ...@@ -1480,7 +1480,7 @@ public class ProxyGenerator {
if (i > 0) { if (i > 0) {
sig.append(','); sig.append(',');
} }
Class parameterType = parameterTypes[i]; Class<?> parameterType = parameterTypes[i];
int dimensions = 0; int dimensions = 0;
while (parameterType.isArray()) { while (parameterType.isArray()) {
parameterType = parameterType.getComponentType(); parameterType = parameterType.getComponentType();
...@@ -1504,7 +1504,7 @@ public class ProxyGenerator { ...@@ -1504,7 +1504,7 @@ public class ProxyGenerator {
* this abstract notion of a "word" in section 3.4, but that definition * this abstract notion of a "word" in section 3.4, but that definition
* was removed for the second edition. * was removed for the second edition.
*/ */
private static int getWordsPerType(Class type) { private static int getWordsPerType(Class<?> type) {
if (type == long.class || type == double.class) { if (type == long.class || type == double.class) {
return 2; return 2;
} else { } else {
...@@ -1632,8 +1632,7 @@ public class ProxyGenerator { ...@@ -1632,8 +1632,7 @@ public class ProxyGenerator {
/** descriptor of same method */ /** descriptor of same method */
public String unwrapMethodDesc; public String unwrapMethodDesc;
private static Map<Class,PrimitiveTypeInfo> table = private static Map<Class<?>,PrimitiveTypeInfo> table = new HashMap<>();
new HashMap<Class,PrimitiveTypeInfo>();
static { static {
add(byte.class, Byte.class); add(byte.class, Byte.class);
add(char.class, Character.class); add(char.class, Character.class);
...@@ -1645,12 +1644,12 @@ public class ProxyGenerator { ...@@ -1645,12 +1644,12 @@ public class ProxyGenerator {
add(boolean.class, Boolean.class); add(boolean.class, Boolean.class);
} }
private static void add(Class primitiveClass, Class wrapperClass) { private static void add(Class<?> primitiveClass, Class<?> wrapperClass) {
table.put(primitiveClass, table.put(primitiveClass,
new PrimitiveTypeInfo(primitiveClass, wrapperClass)); new PrimitiveTypeInfo(primitiveClass, wrapperClass));
} }
private PrimitiveTypeInfo(Class primitiveClass, Class wrapperClass) { private PrimitiveTypeInfo(Class<?> primitiveClass, Class<?> wrapperClass) {
assert primitiveClass.isPrimitive(); assert primitiveClass.isPrimitive();
baseTypeString = baseTypeString =
...@@ -1663,7 +1662,7 @@ public class ProxyGenerator { ...@@ -1663,7 +1662,7 @@ public class ProxyGenerator {
unwrapMethodDesc = "()" + baseTypeString; unwrapMethodDesc = "()" + baseTypeString;
} }
public static PrimitiveTypeInfo get(Class cl) { public static PrimitiveTypeInfo get(Class<?> cl) {
return table.get(cl); return table.get(cl);
} }
} }
...@@ -1694,7 +1693,7 @@ public class ProxyGenerator { ...@@ -1694,7 +1693,7 @@ public class ProxyGenerator {
* and for assigning the next index value. Note that element 0 * and for assigning the next index value. Note that element 0
* of this list corresponds to constant pool index 1. * of this list corresponds to constant pool index 1.
*/ */
private List<Entry> pool = new ArrayList<Entry>(32); private List<Entry> pool = new ArrayList<>(32);
/** /**
* maps constant pool data of all types to constant pool indexes. * maps constant pool data of all types to constant pool indexes.
...@@ -1702,7 +1701,7 @@ public class ProxyGenerator { ...@@ -1702,7 +1701,7 @@ public class ProxyGenerator {
* This map is used to look up the index of an existing entry for * This map is used to look up the index of an existing entry for
* values of all types. * values of all types.
*/ */
private Map<Object,Short> map = new HashMap<Object,Short>(16); private Map<Object,Short> map = new HashMap<>(16);
/** true if no new constant pool entries may be added */ /** true if no new constant pool entries may be added */
private boolean readOnly = false; private boolean readOnly = false;
......
...@@ -125,13 +125,13 @@ import java.util.TreeSet; ...@@ -125,13 +125,13 @@ import java.util.TreeSet;
* @since 1.3 * @since 1.3
*/ */
public final class Service { public final class Service<S> {
private static final String prefix = "META-INF/services/"; private static final String prefix = "META-INF/services/";
private Service() { } private Service() { }
private static void fail(Class service, String msg, Throwable cause) private static void fail(Class<?> service, String msg, Throwable cause)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
ServiceConfigurationError sce ServiceConfigurationError sce
...@@ -140,13 +140,13 @@ public final class Service { ...@@ -140,13 +140,13 @@ public final class Service {
throw sce; throw sce;
} }
private static void fail(Class service, String msg) private static void fail(Class<?> service, String msg)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
throw new ServiceConfigurationError(service.getName() + ": " + msg); throw new ServiceConfigurationError(service.getName() + ": " + msg);
} }
private static void fail(Class service, URL u, int line, String msg) private static void fail(Class<?> service, URL u, int line, String msg)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
fail(service, u + ":" + line + ": " + msg); fail(service, u + ":" + line + ": " + msg);
...@@ -157,8 +157,8 @@ public final class Service { ...@@ -157,8 +157,8 @@ public final class Service {
* on the line to both the names list and the returned set iff the name is * on the line to both the names list and the returned set iff the name is
* not already a member of the returned set. * not already a member of the returned set.
*/ */
private static int parseLine(Class service, URL u, BufferedReader r, int lc, private static int parseLine(Class<?> service, URL u, BufferedReader r, int lc,
List names, Set returned) List<String> names, Set<String> returned)
throws IOException, ServiceConfigurationError throws IOException, ServiceConfigurationError
{ {
String ln = r.readLine(); String ln = r.readLine();
...@@ -211,12 +211,12 @@ public final class Service { ...@@ -211,12 +211,12 @@ public final class Service {
* If an I/O error occurs while reading from the given URL, or * If an I/O error occurs while reading from the given URL, or
* if a configuration-file format error is detected * if a configuration-file format error is detected
*/ */
private static Iterator parse(Class service, URL u, Set returned) private static Iterator<String> parse(Class<?> service, URL u, Set<String> returned)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
InputStream in = null; InputStream in = null;
BufferedReader r = null; BufferedReader r = null;
ArrayList names = new ArrayList(); ArrayList<String> names = new ArrayList<>();
try { try {
in = u.openStream(); in = u.openStream();
r = new BufferedReader(new InputStreamReader(in, "utf-8")); r = new BufferedReader(new InputStreamReader(in, "utf-8"));
...@@ -239,16 +239,16 @@ public final class Service { ...@@ -239,16 +239,16 @@ public final class Service {
/** /**
* Private inner class implementing fully-lazy provider lookup * Private inner class implementing fully-lazy provider lookup
*/ */
private static class LazyIterator implements Iterator { private static class LazyIterator<S> implements Iterator<S> {
Class service; Class<S> service;
ClassLoader loader; ClassLoader loader;
Enumeration configs = null; Enumeration<URL> configs = null;
Iterator pending = null; Iterator<String> pending = null;
Set returned = new TreeSet(); Set<String> returned = new TreeSet<>();
String nextName = null; String nextName = null;
private LazyIterator(Class service, ClassLoader loader) { private LazyIterator(Class<S> service, ClassLoader loader) {
this.service = service; this.service = service;
this.loader = loader; this.loader = loader;
} }
...@@ -272,20 +272,20 @@ public final class Service { ...@@ -272,20 +272,20 @@ public final class Service {
if (!configs.hasMoreElements()) { if (!configs.hasMoreElements()) {
return false; return false;
} }
pending = parse(service, (URL)configs.nextElement(), returned); pending = parse(service, configs.nextElement(), returned);
} }
nextName = (String)pending.next(); nextName = pending.next();
return true; return true;
} }
public Object next() throws ServiceConfigurationError { public S next() throws ServiceConfigurationError {
if (!hasNext()) { if (!hasNext()) {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
String cn = nextName; String cn = nextName;
nextName = null; nextName = null;
try { try {
return Class.forName(cn, true, loader).newInstance(); return service.cast(Class.forName(cn, true, loader).newInstance());
} catch (ClassNotFoundException x) { } catch (ClassNotFoundException x) {
fail(service, fail(service,
"Provider " + cn + " not found"); "Provider " + cn + " not found");
...@@ -342,10 +342,10 @@ public final class Service { ...@@ -342,10 +342,10 @@ public final class Service {
* @see #providers(java.lang.Class) * @see #providers(java.lang.Class)
* @see #installedProviders(java.lang.Class) * @see #installedProviders(java.lang.Class)
*/ */
public static Iterator providers(Class service, ClassLoader loader) public static <S> Iterator<S> providers(Class<S> service, ClassLoader loader)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
return new LazyIterator(service, loader); return new LazyIterator<S>(service, loader);
} }
...@@ -374,7 +374,7 @@ public final class Service { ...@@ -374,7 +374,7 @@ public final class Service {
* *
* @see #providers(java.lang.Class, java.lang.ClassLoader) * @see #providers(java.lang.Class, java.lang.ClassLoader)
*/ */
public static Iterator providers(Class service) public static <S> Iterator<S> providers(Class<S> service)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
ClassLoader cl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = Thread.currentThread().getContextClassLoader();
...@@ -411,7 +411,7 @@ public final class Service { ...@@ -411,7 +411,7 @@ public final class Service {
* *
* @see #providers(java.lang.Class, java.lang.ClassLoader) * @see #providers(java.lang.Class, java.lang.ClassLoader)
*/ */
public static Iterator installedProviders(Class service) public static <S> Iterator<S> installedProviders(Class<S> service)
throws ServiceConfigurationError throws ServiceConfigurationError
{ {
ClassLoader cl = ClassLoader.getSystemClassLoader(); ClassLoader cl = ClassLoader.getSystemClassLoader();
......
...@@ -72,8 +72,8 @@ import java.util.Hashtable; ...@@ -72,8 +72,8 @@ import java.util.Hashtable;
* @since 1.2 * @since 1.2
*/ */
public final class Signal { public final class Signal {
private static Hashtable handlers = new Hashtable(4); private static Hashtable<Signal,SignalHandler> handlers = new Hashtable<>(4);
private static Hashtable signals = new Hashtable(4); private static Hashtable<Integer,Signal> signals = new Hashtable<>(4);
private int number; private int number;
private String name; private String name;
...@@ -166,9 +166,9 @@ public final class Signal { ...@@ -166,9 +166,9 @@ public final class Signal {
throw new IllegalArgumentException throw new IllegalArgumentException
("Signal already used by VM or OS: " + sig); ("Signal already used by VM or OS: " + sig);
} }
signals.put(new Integer(sig.number), sig); signals.put(sig.number, sig);
synchronized (handlers) { synchronized (handlers) {
SignalHandler oldHandler = (SignalHandler)handlers.get(sig); SignalHandler oldHandler = handlers.get(sig);
handlers.remove(sig); handlers.remove(sig);
if (newH == 2) { if (newH == 2) {
handlers.put(sig, handler); handlers.put(sig, handler);
...@@ -200,8 +200,8 @@ public final class Signal { ...@@ -200,8 +200,8 @@ public final class Signal {
/* Called by the VM to execute Java signal handlers. */ /* Called by the VM to execute Java signal handlers. */
private static void dispatch(final int number) { private static void dispatch(final int number) {
final Signal sig = (Signal)signals.get(new Integer(number)); final Signal sig = signals.get(number);
final SignalHandler handler = (SignalHandler)handlers.get(sig); final SignalHandler handler = handlers.get(sig);
Runnable runnable = new Runnable () { Runnable runnable = new Runnable () {
public void run() { public void run() {
......
...@@ -154,8 +154,7 @@ public class Basic { ...@@ -154,8 +154,7 @@ public class Basic {
/* run javac <args> */ /* run javac <args> */
static void compile(String... args) { static void compile(String... args) {
debug("Running: javac " + Arrays.toString(args)); debug("Running: javac " + Arrays.toString(args));
com.sun.tools.javac.Main compiler = new com.sun.tools.javac.Main(); if (com.sun.tools.javac.Main.compile(args) != 0) {
if (compiler.compile(args) != 0) {
throw new RuntimeException("javac failed: args=" + Arrays.toString(args)); throw new RuntimeException("javac failed: args=" + Arrays.toString(args));
} }
} }
...@@ -259,7 +258,7 @@ public class Basic { ...@@ -259,7 +258,7 @@ public class Basic {
URLClassLoader loader = getLoader(baseURL); URLClassLoader loader = getLoader(baseURL);
httpServer.reset(); httpServer.reset();
Class messageServiceClass = null; Class<?> messageServiceClass = null;
try { try {
messageServiceClass = loader.loadClass(serviceClass); messageServiceClass = loader.loadClass(serviceClass);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
...@@ -267,7 +266,7 @@ public class Basic { ...@@ -267,7 +266,7 @@ public class Basic {
throw new RuntimeException("Error in test: " + cnfe); throw new RuntimeException("Error in test: " + cnfe);
} }
Iterator<Class<?>> iterator = sun.misc.Service.providers(messageServiceClass, loader); Iterator<?> iterator = sun.misc.Service.providers(messageServiceClass, loader);
if (expectToFind && !iterator.hasNext()) { if (expectToFind && !iterator.hasNext()) {
debug(messageServiceClass + " NOT found."); debug(messageServiceClass + " NOT found.");
return false; return false;
...@@ -301,7 +300,7 @@ public class Basic { ...@@ -301,7 +300,7 @@ public class Basic {
URLClassLoader loader = getLoader(baseURL); URLClassLoader loader = getLoader(baseURL);
httpServer.reset(); httpServer.reset();
Class messageServiceClass = null; Class<?> messageServiceClass = null;
try { try {
messageServiceClass = loader.loadClass(serviceClass); messageServiceClass = loader.loadClass(serviceClass);
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
...@@ -309,7 +308,7 @@ public class Basic { ...@@ -309,7 +308,7 @@ public class Basic {
throw new RuntimeException("Error in test: " + cnfe); throw new RuntimeException("Error in test: " + cnfe);
} }
Iterator<Class<?>> iterator = (ServiceLoader.load(messageServiceClass, loader)).iterator(); Iterator<?> iterator = (ServiceLoader.load(messageServiceClass, loader)).iterator();
if (expectToFind && !iterator.hasNext()) { if (expectToFind && !iterator.hasNext()) {
debug(messageServiceClass + " NOT found."); debug(messageServiceClass + " NOT found.");
return false; return false;
...@@ -345,7 +344,7 @@ public class Basic { ...@@ -345,7 +344,7 @@ public class Basic {
URLClassLoader loader = getLoader(baseURL); URLClassLoader loader = getLoader(baseURL);
httpServer.reset(); httpServer.reset();
Class ADotAKlass = null; Class<?> ADotAKlass = null;
try { try {
ADotAKlass = loader.loadClass("a.A"); ADotAKlass = loader.loadClass("a.A");
} catch (ClassNotFoundException cnfe) { } catch (ClassNotFoundException cnfe) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册