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