提交 322c6102 编写于 作者: O omajid

7117612: Miscellaneous warnings in java.lang

Reviewed-by: smarks, dholmes, alanb, darcy
上级 808a9fe5
...@@ -60,7 +60,8 @@ public final class Boolean implements java.io.Serializable, ...@@ -60,7 +60,8 @@ public final class Boolean implements java.io.Serializable,
* *
* @since JDK1.1 * @since JDK1.1
*/ */
public static final Class<Boolean> TYPE = Class.getPrimitiveClass("boolean"); @SuppressWarnings("unchecked")
public static final Class<Boolean> TYPE = (Class<Boolean>) Class.getPrimitiveClass("boolean");
/** /**
* The value of the Boolean. * The value of the Boolean.
......
...@@ -59,6 +59,7 @@ public final class Byte extends Number implements Comparable<Byte> { ...@@ -59,6 +59,7 @@ public final class Byte extends Number implements Comparable<Byte> {
* The {@code Class} instance representing the primitive type * The {@code Class} instance representing the primitive type
* {@code byte}. * {@code byte}.
*/ */
@SuppressWarnings("unchecked")
public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte"); public static final Class<Byte> TYPE = (Class<Byte>) Class.getPrimitiveClass("byte");
/** /**
......
...@@ -172,7 +172,7 @@ class Character implements java.io.Serializable, Comparable<Character> { ...@@ -172,7 +172,7 @@ class Character implements java.io.Serializable, Comparable<Character> {
* @since 1.1 * @since 1.1
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static final Class<Character> TYPE = Class.getPrimitiveClass("char"); public static final Class<Character> TYPE = (Class<Character>) Class.getPrimitiveClass("char");
/* /*
* Normative general types * Normative general types
......
...@@ -101,6 +101,8 @@ class CharacterName { ...@@ -101,6 +101,8 @@ class CharacterName {
if (lookup[cp>>8] == null || if (lookup[cp>>8] == null ||
(off = lookup[cp>>8][cp&0xff]) == 0) (off = lookup[cp>>8][cp&0xff]) == 0)
return null; return null;
return new String(strPool, 0, off >>> 8, off & 0xff); // ASCII @SuppressWarnings("deprecation")
String result = new String(strPool, 0, off >>> 8, off & 0xff); // ASCII
return result;
} }
} }
...@@ -631,6 +631,7 @@ public final ...@@ -631,6 +631,7 @@ public final
* <cite>The Java&trade; Virtual Machine Specification</cite> * <cite>The Java&trade; Virtual Machine Specification</cite>
* @since 1.5 * @since 1.5
*/ */
@SuppressWarnings("unchecked")
public TypeVariable<Class<T>>[] getTypeParameters() { public TypeVariable<Class<T>>[] getTypeParameters() {
if (getGenericSignature() != null) if (getGenericSignature() != null)
return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters(); return (TypeVariable<Class<T>>[])getGenericInfo().getTypeParameters();
...@@ -1303,7 +1304,7 @@ public final ...@@ -1303,7 +1304,7 @@ public final
return java.security.AccessController.doPrivileged( return java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Class<?>[]>() { new java.security.PrivilegedAction<Class<?>[]>() {
public Class[] run() { public Class<?>[] run() {
List<Class<?>> list = new ArrayList<>(); List<Class<?>> list = new ArrayList<>();
Class<?> currentClass = Class.this; Class<?> currentClass = Class.this;
while (currentClass != null) { while (currentClass != null) {
...@@ -1315,7 +1316,7 @@ public final ...@@ -1315,7 +1316,7 @@ public final
} }
currentClass = currentClass.getSuperclass(); currentClass = currentClass.getSuperclass();
} }
return list.toArray(new Class[0]); return list.toArray(new Class<?>[0]);
} }
}); });
} }
...@@ -2150,7 +2151,7 @@ public final ...@@ -2150,7 +2151,7 @@ public final
* Return the Virtual Machine's Class object for the named * Return the Virtual Machine's Class object for the named
* primitive type. * primitive type.
*/ */
static native Class getPrimitiveClass(String name); static native Class<?> getPrimitiveClass(String name);
/* /*
...@@ -2395,7 +2396,9 @@ public final ...@@ -2395,7 +2396,9 @@ public final
} }
// No cached value available; request value from VM // No cached value available; request value from VM
if (isInterface()) { if (isInterface()) {
res = new Constructor[0]; @SuppressWarnings("unchecked")
Constructor<T>[] temporaryRes = (Constructor<T>[]) new Constructor<?>[0];
res = temporaryRes;
} else { } else {
res = getDeclaredConstructors0(publicOnly); res = getDeclaredConstructors0(publicOnly);
} }
...@@ -2951,7 +2954,9 @@ public final ...@@ -2951,7 +2954,9 @@ public final
return null; return null;
} }
}); });
enumConstants = (T[])values.invoke(null); @SuppressWarnings("unchecked")
T[] temporaryConstants = (T[])values.invoke(null);
enumConstants = temporaryConstants;
} }
// These can happen when users concoct enum-like classes // These can happen when users concoct enum-like classes
// that don't comply with the enum spec. // that don't comply with the enum spec.
...@@ -2996,6 +3001,7 @@ public final ...@@ -2996,6 +3001,7 @@ public final
* *
* @since 1.5 * @since 1.5
*/ */
@SuppressWarnings("unchecked")
public T cast(Object obj) { public T cast(Object obj) {
if (obj != null && !isInstance(obj)) if (obj != null && !isInstance(obj))
throw new ClassCastException(cannotCastMsg(obj)); throw new ClassCastException(cannotCastMsg(obj));
...@@ -3026,6 +3032,7 @@ public final ...@@ -3026,6 +3032,7 @@ public final
* the class itself). * the class itself).
* @since 1.5 * @since 1.5
*/ */
@SuppressWarnings("unchecked")
public <U> Class<? extends U> asSubclass(Class<U> clazz) { public <U> Class<? extends U> asSubclass(Class<U> clazz) {
if (clazz.isAssignableFrom(this)) if (clazz.isAssignableFrom(this))
return (Class<? extends U>) this; return (Class<? extends U>) this;
...@@ -3037,6 +3044,7 @@ public final ...@@ -3037,6 +3044,7 @@ public final
* @throws NullPointerException {@inheritDoc} * @throws NullPointerException {@inheritDoc}
* @since 1.5 * @since 1.5
*/ */
@SuppressWarnings("unchecked")
public <A extends Annotation> A getAnnotation(Class<A> annotationClass) { public <A extends Annotation> A getAnnotation(Class<A> annotationClass) {
if (annotationClass == null) if (annotationClass == null)
throw new NullPointerException(); throw new NullPointerException();
......
...@@ -1167,7 +1167,8 @@ public abstract class ClassLoader { ...@@ -1167,7 +1167,8 @@ public abstract class ClassLoader {
* @since 1.2 * @since 1.2
*/ */
public Enumeration<URL> getResources(String name) throws IOException { public Enumeration<URL> getResources(String name) throws IOException {
Enumeration[] tmp = new Enumeration[2]; @SuppressWarnings("unchecked")
Enumeration<URL>[] tmp = (Enumeration<URL>[]) new Enumeration<?>[2];
if (parent != null) { if (parent != null) {
tmp[0] = parent.getResources(name); tmp[0] = parent.getResources(name);
} else { } else {
......
...@@ -92,15 +92,15 @@ final class ConditionalSpecialCasing { ...@@ -92,15 +92,15 @@ final class ConditionalSpecialCasing {
}; };
// A hash table that contains the above entries // A hash table that contains the above entries
static Hashtable entryTable = new Hashtable(); static Hashtable<Integer, HashSet<Entry>> entryTable = new Hashtable<>();
static { static {
// create hashtable from the entry // create hashtable from the entry
for (int i = 0; i < entry.length; i ++) { for (int i = 0; i < entry.length; i ++) {
Entry cur = entry[i]; Entry cur = entry[i];
Integer cp = new Integer(cur.getCodePoint()); Integer cp = new Integer(cur.getCodePoint());
HashSet set = (HashSet)entryTable.get(cp); HashSet<Entry> set = entryTable.get(cp);
if (set == null) { if (set == null) {
set = new HashSet(); set = new HashSet<Entry>();
} }
set.add(cur); set.add(cur);
entryTable.put(cp, set); entryTable.put(cp, set);
...@@ -151,13 +151,13 @@ final class ConditionalSpecialCasing { ...@@ -151,13 +151,13 @@ final class ConditionalSpecialCasing {
} }
private static char[] lookUpTable(String src, int index, Locale locale, boolean bLowerCasing) { private static char[] lookUpTable(String src, int index, Locale locale, boolean bLowerCasing) {
HashSet set = (HashSet)entryTable.get(new Integer(src.codePointAt(index))); HashSet<Entry> set = entryTable.get(new Integer(src.codePointAt(index)));
if (set != null) { if (set != null) {
Iterator iter = set.iterator(); Iterator<Entry> iter = set.iterator();
String currentLang = locale.getLanguage(); String currentLang = locale.getLanguage();
while (iter.hasNext()) { while (iter.hasNext()) {
Entry entry = (Entry)iter.next(); Entry entry = iter.next();
String conditionLang= entry.getLanguage(); String conditionLang= entry.getLanguage();
if (((conditionLang == null) || (conditionLang.equals(currentLang))) && if (((conditionLang == null) || (conditionLang.equals(currentLang))) &&
isConditionMet(src, index, locale, entry.getCondition())) { isConditionMet(src, index, locale, entry.getCondition())) {
......
...@@ -128,6 +128,7 @@ public final class Double extends Number implements Comparable<Double> { ...@@ -128,6 +128,7 @@ public final class Double extends Number implements Comparable<Double> {
* *
* @since JDK1.1 * @since JDK1.1
*/ */
@SuppressWarnings("unchecked")
public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double"); public static final Class<Double> TYPE = (Class<Double>) Class.getPrimitiveClass("double");
/** /**
...@@ -715,7 +716,7 @@ public final class Double extends Number implements Comparable<Double> { ...@@ -715,7 +716,7 @@ public final class Double extends Number implements Comparable<Double> {
* @return the {@code double} value represented by this object * @return the {@code double} value represented by this object
*/ */
public double doubleValue() { public double doubleValue() {
return (double)value; return value;
} }
/** /**
......
...@@ -36,6 +36,7 @@ package java.lang; ...@@ -36,6 +36,7 @@ package java.lang;
* @see java.lang.reflect.AnnotatedElement * @see java.lang.reflect.AnnotatedElement
* @since 1.5 * @since 1.5
*/ */
@SuppressWarnings("rawtypes") /* rawtypes are part of the public api */
public class EnumConstantNotPresentException extends RuntimeException { public class EnumConstantNotPresentException extends RuntimeException {
private static final long serialVersionUID = -6046998521960521108L; private static final long serialVersionUID = -6046998521960521108L;
......
...@@ -126,7 +126,8 @@ public final class Float extends Number implements Comparable<Float> { ...@@ -126,7 +126,8 @@ public final class Float extends Number implements Comparable<Float> {
* *
* @since JDK1.1 * @since JDK1.1
*/ */
public static final Class<Float> TYPE = Class.getPrimitiveClass("float"); @SuppressWarnings("unchecked")
public static final Class<Float> TYPE = (Class<Float>) Class.getPrimitiveClass("float");
/** /**
* Returns a string representation of the {@code float} * Returns a string representation of the {@code float}
......
...@@ -68,6 +68,7 @@ public final class Integer extends Number implements Comparable<Integer> { ...@@ -68,6 +68,7 @@ public final class Integer extends Number implements Comparable<Integer> {
* *
* @since JDK1.1 * @since JDK1.1
*/ */
@SuppressWarnings("unchecked")
public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int"); public static final Class<Integer> TYPE = (Class<Integer>) Class.getPrimitiveClass("int");
/** /**
......
...@@ -66,6 +66,7 @@ public final class Long extends Number implements Comparable<Long> { ...@@ -66,6 +66,7 @@ public final class Long extends Number implements Comparable<Long> {
* *
* @since JDK1.1 * @since JDK1.1
*/ */
@SuppressWarnings("unchecked")
public static final Class<Long> TYPE = (Class<Long>) Class.getPrimitiveClass("long"); public static final Class<Long> TYPE = (Class<Long>) Class.getPrimitiveClass("long");
/** /**
...@@ -734,7 +735,7 @@ public final class Long extends Number implements Comparable<Long> { ...@@ -734,7 +735,7 @@ public final class Long extends Number implements Comparable<Long> {
* {@code long} value. * {@code long} value.
*/ */
public long longValue() { public long longValue() {
return (long)value; return value;
} }
/** /**
......
...@@ -58,6 +58,7 @@ public final class Short extends Number implements Comparable<Short> { ...@@ -58,6 +58,7 @@ public final class Short extends Number implements Comparable<Short> {
* The {@code Class} instance representing the primitive type * The {@code Class} instance representing the primitive type
* {@code short}. * {@code short}.
*/ */
@SuppressWarnings("unchecked")
public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short"); public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short");
/** /**
......
...@@ -1032,7 +1032,7 @@ public final class System { ...@@ -1032,7 +1032,7 @@ public final class System {
*/ */
@Deprecated @Deprecated
public static void runFinalizersOnExit(boolean value) { public static void runFinalizersOnExit(boolean value) {
Runtime.getRuntime().runFinalizersOnExit(value); Runtime.runFinalizersOnExit(value);
} }
/** /**
......
...@@ -144,8 +144,11 @@ public class ThreadLocal<T> { ...@@ -144,8 +144,11 @@ public class ThreadLocal<T> {
ThreadLocalMap map = getMap(t); ThreadLocalMap map = getMap(t);
if (map != null) { if (map != null) {
ThreadLocalMap.Entry e = map.getEntry(this); ThreadLocalMap.Entry e = map.getEntry(this);
if (e != null) if (e != null) {
return (T)e.value; @SuppressWarnings("unchecked")
T result = (T)e.value;
return result;
}
} }
return setInitialValue(); return setInitialValue();
} }
...@@ -268,11 +271,11 @@ public class ThreadLocal<T> { ...@@ -268,11 +271,11 @@ public class ThreadLocal<T> {
* entry can be expunged from table. Such entries are referred to * entry can be expunged from table. Such entries are referred to
* as "stale entries" in the code that follows. * as "stale entries" in the code that follows.
*/ */
static class Entry extends WeakReference<ThreadLocal> { static class Entry extends WeakReference<ThreadLocal<?>> {
/** The value associated with this ThreadLocal. */ /** The value associated with this ThreadLocal. */
Object value; Object value;
Entry(ThreadLocal k, Object v) { Entry(ThreadLocal<?> k, Object v) {
super(k); super(k);
value = v; value = v;
} }
...@@ -325,7 +328,7 @@ public class ThreadLocal<T> { ...@@ -325,7 +328,7 @@ public class ThreadLocal<T> {
* ThreadLocalMaps are constructed lazily, so we only create * ThreadLocalMaps are constructed lazily, so we only create
* one when we have at least one entry to put in it. * one when we have at least one entry to put in it.
*/ */
ThreadLocalMap(ThreadLocal firstKey, Object firstValue) { ThreadLocalMap(ThreadLocal<?> firstKey, Object firstValue) {
table = new Entry[INITIAL_CAPACITY]; table = new Entry[INITIAL_CAPACITY];
int i = firstKey.threadLocalHashCode & (INITIAL_CAPACITY - 1); int i = firstKey.threadLocalHashCode & (INITIAL_CAPACITY - 1);
table[i] = new Entry(firstKey, firstValue); table[i] = new Entry(firstKey, firstValue);
...@@ -348,7 +351,8 @@ public class ThreadLocal<T> { ...@@ -348,7 +351,8 @@ public class ThreadLocal<T> {
for (int j = 0; j < len; j++) { for (int j = 0; j < len; j++) {
Entry e = parentTable[j]; Entry e = parentTable[j];
if (e != null) { if (e != null) {
ThreadLocal key = e.get(); @SuppressWarnings("unchecked")
ThreadLocal<Object> key = (ThreadLocal<Object>) e.get();
if (key != null) { if (key != null) {
Object value = key.childValue(e.value); Object value = key.childValue(e.value);
Entry c = new Entry(key, value); Entry c = new Entry(key, value);
...@@ -372,7 +376,7 @@ public class ThreadLocal<T> { ...@@ -372,7 +376,7 @@ public class ThreadLocal<T> {
* @param key the thread local object * @param key the thread local object
* @return the entry associated with key, or null if no such * @return the entry associated with key, or null if no such
*/ */
private Entry getEntry(ThreadLocal key) { private Entry getEntry(ThreadLocal<?> key) {
int i = key.threadLocalHashCode & (table.length - 1); int i = key.threadLocalHashCode & (table.length - 1);
Entry e = table[i]; Entry e = table[i];
if (e != null && e.get() == key) if (e != null && e.get() == key)
...@@ -390,12 +394,12 @@ public class ThreadLocal<T> { ...@@ -390,12 +394,12 @@ public class ThreadLocal<T> {
* @param e the entry at table[i] * @param e the entry at table[i]
* @return the entry associated with key, or null if no such * @return the entry associated with key, or null if no such
*/ */
private Entry getEntryAfterMiss(ThreadLocal key, int i, Entry e) { private Entry getEntryAfterMiss(ThreadLocal<?> key, int i, Entry e) {
Entry[] tab = table; Entry[] tab = table;
int len = tab.length; int len = tab.length;
while (e != null) { while (e != null) {
ThreadLocal k = e.get(); ThreadLocal<?> k = e.get();
if (k == key) if (k == key)
return e; return e;
if (k == null) if (k == null)
...@@ -413,7 +417,7 @@ public class ThreadLocal<T> { ...@@ -413,7 +417,7 @@ public class ThreadLocal<T> {
* @param key the thread local object * @param key the thread local object
* @param value the value to be set * @param value the value to be set
*/ */
private void set(ThreadLocal key, Object value) { private void set(ThreadLocal<?> key, Object value) {
// We don't use a fast path as with get() because it is at // We don't use a fast path as with get() because it is at
// least as common to use set() to create new entries as // least as common to use set() to create new entries as
...@@ -427,7 +431,7 @@ public class ThreadLocal<T> { ...@@ -427,7 +431,7 @@ public class ThreadLocal<T> {
for (Entry e = tab[i]; for (Entry e = tab[i];
e != null; e != null;
e = tab[i = nextIndex(i, len)]) { e = tab[i = nextIndex(i, len)]) {
ThreadLocal k = e.get(); ThreadLocal<?> k = e.get();
if (k == key) { if (k == key) {
e.value = value; e.value = value;
...@@ -449,7 +453,7 @@ public class ThreadLocal<T> { ...@@ -449,7 +453,7 @@ public class ThreadLocal<T> {
/** /**
* Remove the entry for key. * Remove the entry for key.
*/ */
private void remove(ThreadLocal key) { private void remove(ThreadLocal<?> key) {
Entry[] tab = table; Entry[] tab = table;
int len = tab.length; int len = tab.length;
int i = key.threadLocalHashCode & (len-1); int i = key.threadLocalHashCode & (len-1);
...@@ -479,7 +483,7 @@ public class ThreadLocal<T> { ...@@ -479,7 +483,7 @@ public class ThreadLocal<T> {
* @param staleSlot index of the first stale entry encountered while * @param staleSlot index of the first stale entry encountered while
* searching for key. * searching for key.
*/ */
private void replaceStaleEntry(ThreadLocal key, Object value, private void replaceStaleEntry(ThreadLocal<?> key, Object value,
int staleSlot) { int staleSlot) {
Entry[] tab = table; Entry[] tab = table;
int len = tab.length; int len = tab.length;
...@@ -501,7 +505,7 @@ public class ThreadLocal<T> { ...@@ -501,7 +505,7 @@ public class ThreadLocal<T> {
for (int i = nextIndex(staleSlot, len); for (int i = nextIndex(staleSlot, len);
(e = tab[i]) != null; (e = tab[i]) != null;
i = nextIndex(i, len)) { i = nextIndex(i, len)) {
ThreadLocal k = e.get(); ThreadLocal<?> k = e.get();
// If we find key, then we need to swap it // If we find key, then we need to swap it
// with the stale entry to maintain hash table order. // with the stale entry to maintain hash table order.
...@@ -563,7 +567,7 @@ public class ThreadLocal<T> { ...@@ -563,7 +567,7 @@ public class ThreadLocal<T> {
for (i = nextIndex(staleSlot, len); for (i = nextIndex(staleSlot, len);
(e = tab[i]) != null; (e = tab[i]) != null;
i = nextIndex(i, len)) { i = nextIndex(i, len)) {
ThreadLocal k = e.get(); ThreadLocal<?> k = e.get();
if (k == null) { if (k == null) {
e.value = null; e.value = null;
tab[i] = null; tab[i] = null;
...@@ -650,7 +654,7 @@ public class ThreadLocal<T> { ...@@ -650,7 +654,7 @@ public class ThreadLocal<T> {
for (int j = 0; j < oldLen; ++j) { for (int j = 0; j < oldLen; ++j) {
Entry e = oldTab[j]; Entry e = oldTab[j];
if (e != null) { if (e != null) {
ThreadLocal k = e.get(); ThreadLocal<?> k = e.get();
if (k == null) { if (k == null) {
e.value = null; // Help the GC e.value = null; // Help the GC
} else { } else {
......
...@@ -40,7 +40,8 @@ class Void { ...@@ -40,7 +40,8 @@ class Void {
* The {@code Class} object representing the pseudo-type corresponding to * The {@code Class} object representing the pseudo-type corresponding to
* the keyword {@code void}. * the keyword {@code void}.
*/ */
public static final Class<Void> TYPE = Class.getPrimitiveClass("void"); @SuppressWarnings("unchecked")
public static final Class<Void> TYPE = (Class<Void>) Class.getPrimitiveClass("void");
/* /*
* The Void class cannot be instantiated. * The Void class cannot be instantiated.
......
...@@ -91,6 +91,7 @@ final class ProcessEnvironment ...@@ -91,6 +91,7 @@ final class ProcessEnvironment
} }
/* Only for use by ProcessBuilder.environment() */ /* Only for use by ProcessBuilder.environment() */
@SuppressWarnings("unchecked")
static Map<String,String> environment() { static Map<String,String> environment() {
return new StringEnvironment return new StringEnvironment
((Map<Variable,Value>)(theEnvironment.clone())); ((Map<Variable,Value>)(theEnvironment.clone()));
......
...@@ -68,6 +68,9 @@ import java.util.*; ...@@ -68,6 +68,9 @@ import java.util.*;
final class ProcessEnvironment extends HashMap<String,String> final class ProcessEnvironment extends HashMap<String,String>
{ {
private static final long serialVersionUID = -8017839552603542824L;
private static String validateName(String name) { private static String validateName(String name) {
// An initial `=' indicates a magic Windows variable name -- OK // An initial `=' indicates a magic Windows variable name -- OK
if (name.indexOf('=', 1) != -1 || if (name.indexOf('=', 1) != -1 ||
...@@ -144,6 +147,7 @@ final class ProcessEnvironment extends HashMap<String,String> ...@@ -144,6 +147,7 @@ final class ProcessEnvironment extends HashMap<String,String>
}; };
} }
private static Map.Entry<String,String> checkedEntry(Object o) { private static Map.Entry<String,String> checkedEntry(Object o) {
@SuppressWarnings("unchecked")
Map.Entry<String,String> e = (Map.Entry<String,String>) o; Map.Entry<String,String> e = (Map.Entry<String,String>) o;
nonNullString(e.getKey()); nonNullString(e.getKey());
nonNullString(e.getValue()); nonNullString(e.getValue());
...@@ -281,6 +285,7 @@ final class ProcessEnvironment extends HashMap<String,String> ...@@ -281,6 +285,7 @@ final class ProcessEnvironment extends HashMap<String,String>
} }
// Only for use by ProcessBuilder.environment() // Only for use by ProcessBuilder.environment()
@SuppressWarnings("unchecked")
static Map<String,String> environment() { static Map<String,String> environment() {
return (Map<String,String>) theEnvironment.clone(); return (Map<String,String>) theEnvironment.clone();
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册