提交 b2c32782 编写于 作者: D dxu

7193406: Clean-up JDK Build Warnings in java.util, java.io

Summary: Clean-up JDK Build Warnings in java.util, java.io Packages
Reviewed-by: smarks, darcy, khazra, dholmes, forax, dl, andrew, aph, omajid, ulfzibis, christos, mduigou
上级 af4dd469
......@@ -883,7 +883,7 @@ class PackageWriter extends BandStructure {
avHiBits &= (1L<<attrIndexLimit[i])-1;
int nextLoBit = 0;
Map<Attribute.Layout, int[]> defMap = allLayouts.get(i);
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
Map.Entry<Attribute.Layout, int[]>[] layoutsAndCounts =
new Map.Entry[defMap.size()];
defMap.entrySet().toArray(layoutsAndCounts);
......
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2012, 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
......@@ -31,10 +31,6 @@ import java.util.List;
import java.util.ArrayList;
import java.util.Vector;
import java.util.Collections;
import java.io.ObjectStreamField;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import sun.security.util.SecurityConstants;
/**
......@@ -424,7 +420,7 @@ public final class FilePermission extends Permission implements Serializable {
/**
* Converts an actions String to an actions mask.
*
* @param action the action string.
* @param actions the action string.
* @return the actions mask.
*/
private static int getMask(String actions) {
......@@ -435,7 +431,9 @@ public final class FilePermission extends Permission implements Serializable {
if (actions == null) {
return mask;
}
// Check against use of constants (used heavily within the JDK)
// Use object identity comparison against known-interned strings for
// performance benefit (these values are used heavily within the JDK).
if (actions == SecurityConstants.FILE_READ_ACTION) {
return READ;
} else if (actions == SecurityConstants.FILE_WRITE_ACTION) {
......@@ -531,7 +529,7 @@ public final class FilePermission extends Permission implements Serializable {
switch(a[i-matchlen]) {
case ',':
seencomma = true;
/*FALLTHROUGH*/
break;
case ' ': case '\r': case '\n':
case '\f': case '\t':
break;
......@@ -798,7 +796,7 @@ implements Serializable {
* @return an enumeration of all the FilePermission objects.
*/
public Enumeration elements() {
public Enumeration<Permission> elements() {
// Convert Iterator into Enumeration
synchronized (this) {
return Collections.enumeration(perms);
......@@ -843,7 +841,6 @@ implements Serializable {
/*
* Reads in a Vector of FilePermissions and saves them in the perms field.
*/
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
// Don't call defaultReadObject()
......@@ -852,6 +849,7 @@ implements Serializable {
ObjectInputStream.GetField gfields = in.readFields();
// Get the one we want
@SuppressWarnings("unchecked")
Vector<Permission> permissions = (Vector<Permission>)gfields.get("permissions", null);
perms = new ArrayList<>(permissions.size());
perms.addAll(permissions);
......
......@@ -182,7 +182,7 @@ public final class Constructor<T> extends Executable {
* @since 1.5
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public TypeVariable<Constructor<T>>[] getTypeParameters() {
if (getSignature() != null) {
return (TypeVariable<Constructor<T>>[])getGenericInfo().getTypeParameters();
......
......@@ -194,7 +194,7 @@ public final class Method extends Executable {
* @since 1.5
*/
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public TypeVariable<Method>[] getTypeParameters() {
if (getGenericSignature() != null)
return (TypeVariable<Method>[])getGenericInfo().getTypeParameters();
......
......@@ -467,7 +467,6 @@ implements java.io.Serializable
* @param action the action string
* @return the action mask
*/
@SuppressWarnings("fallthrough")
private static int getMask(String action) {
if (action == null) {
......@@ -480,7 +479,8 @@ implements java.io.Serializable
int mask = NONE;
// Check against use of constants (used heavily within the JDK)
// Use object identity comparison against known-interned strings for
// performance benefit (these values are used heavily within the JDK).
if (action == SecurityConstants.SOCKET_RESOLVE_ACTION) {
return RESOLVE;
} else if (action == SecurityConstants.SOCKET_CONNECT_ACTION) {
......@@ -568,7 +568,7 @@ implements java.io.Serializable
switch(a[i-matchlen]) {
case ',':
seencomma = true;
/*FALLTHROUGH*/
break;
case ' ': case '\r': case '\n':
case '\f': case '\t':
break;
......
......@@ -248,7 +248,7 @@ public abstract class AsynchronousFileChannel
return provider.newAsynchronousFileChannel(file, options, executor, attrs);
}
@SuppressWarnings({ "unchecked", "rawtypes" }) // generic array construction
@SuppressWarnings({"unchecked", "rawtypes"}) // generic array construction
private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0];
/**
......
......@@ -287,7 +287,7 @@ public abstract class FileChannel
return provider.newFileChannel(path, options, attrs);
}
@SuppressWarnings({ "unchecked", "rawtypes" }) // generic array construction
@SuppressWarnings({"unchecked", "rawtypes"}) // generic array construction
private static final FileAttribute<?>[] NO_ATTRIBUTES = new FileAttribute[0];
/**
......
......@@ -121,6 +121,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
*
* @param numElements the number of elements to hold
*/
@SuppressWarnings("unchecked")
private void allocateElements(int numElements) {
int initialCapacity = MIN_INITIAL_CAPACITY;
// Find the best power of two to hold elements.
......@@ -152,10 +153,11 @@ public class ArrayDeque<E> extends AbstractCollection<E>
int newCapacity = n << 1;
if (newCapacity < 0)
throw new IllegalStateException("Sorry, deque too big");
Object[] a = new Object[newCapacity];
@SuppressWarnings("unchecked")
E[] a = (E[]) new Object[newCapacity];
System.arraycopy(elements, p, a, 0, r);
System.arraycopy(elements, 0, a, r, p);
elements = (E[])a;
elements = a;
head = 0;
tail = n;
}
......@@ -182,6 +184,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
* Constructs an empty array deque with an initial capacity
* sufficient to hold 16 elements.
*/
@SuppressWarnings("unchecked")
public ArrayDeque() {
elements = (E[]) new Object[16];
}
......@@ -793,6 +796,7 @@ public class ArrayDeque<E> extends AbstractCollection<E>
* this deque
* @throws NullPointerException if the specified array is null
*/
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) {
int size = size();
if (a.length < size)
......
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2012, 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
......@@ -560,7 +560,7 @@ public class Arrays {
* off is the offset to generate corresponding low, high in src
* To be removed in a future release.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
private static void mergeSort(Object[] src,
Object[] dest,
int low,
......@@ -747,7 +747,7 @@ public class Arrays {
* off is the offset into src corresponding to low in dest
* To be removed in a future release.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
private static void mergeSort(Object[] src,
Object[] dest,
int low, int high, int off,
......@@ -2832,6 +2832,7 @@ public class Arrays {
* @return a list view of the specified array
*/
@SafeVarargs
@SuppressWarnings("varargs")
public static <T> List<T> asList(T... a) {
return new ArrayList<>(a);
}
......
......@@ -213,7 +213,7 @@ public class Collections {
* @throws IllegalArgumentException (optional) if the comparator is
* found to violate the {@link Comparator} contract
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T> void sort(List<T> list, Comparator<? super T> c) {
Object[] a = list.toArray();
Arrays.sort(a, (Comparator)c);
......@@ -418,7 +418,7 @@ public class Collections {
* @throws UnsupportedOperationException if the specified list or
* its list-iterator does not support the <tt>set</tt> operation.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void reverse(List<?> list) {
int size = list.size();
if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {
......@@ -497,7 +497,7 @@ public class Collections {
* @throws UnsupportedOperationException if the specified list or its
* list-iterator does not support the <tt>set</tt> operation.
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void shuffle(List<?> list, Random rnd) {
int size = list.size();
if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {
......@@ -535,7 +535,7 @@ public class Collections {
* || j &lt; 0 || j &gt;= list.size()).
* @since 1.4
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({"rawtypes", "unchecked"})
public static void swap(List<?> list, int i, int j) {
// instead of using a raw type here, it's possible to capture
// the wildcard but it will require a call to a supplementary
......@@ -669,7 +669,7 @@ public class Collections {
* @throws NoSuchElementException if the collection is empty.
* @see Comparable
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T> T min(Collection<? extends T> coll, Comparator<? super T> comp) {
if (comp==null)
return (T)min((Collection) coll);
......@@ -740,7 +740,7 @@ public class Collections {
* @throws NoSuchElementException if the collection is empty.
* @see Comparable
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
public static <T> T max(Collection<? extends T> coll, Comparator<? super T> comp) {
if (comp==null)
return (T)max((Collection) coll);
......@@ -1403,7 +1403,7 @@ public class Collections {
extends UnmodifiableSet<Map.Entry<K,V>> {
private static final long serialVersionUID = 7854390611657943733L;
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
UnmodifiableEntrySet(Set<? extends Map.Entry<? extends K, ? extends V>> s) {
// Need to cast to raw in order to work around a limitation in the type system
super((Set)s);
......@@ -3172,7 +3172,7 @@ public class Collections {
*
* @see #emptySet()
*/
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public static final Set EMPTY_SET = new EmptySet<>();
/**
......@@ -3271,10 +3271,13 @@ public class Collections {
return new EmptySortedSet<>();
}
public Comparator comparator() {
@Override
public Comparator<? super E> comparator() {
return null;
}
@Override
@SuppressWarnings("unchecked")
public SortedSet<E> subSet(Object fromElement, Object toElement) {
Objects.requireNonNull(fromElement);
Objects.requireNonNull(toElement);
......@@ -3294,6 +3297,7 @@ public class Collections {
return emptySortedSet();
}
@Override
public SortedSet<E> headSet(Object toElement) {
Objects.requireNonNull(toElement);
......@@ -3304,6 +3308,7 @@ public class Collections {
return emptySortedSet();
}
@Override
public SortedSet<E> tailSet(Object fromElement) {
Objects.requireNonNull(fromElement);
......@@ -3314,10 +3319,12 @@ public class Collections {
return emptySortedSet();
}
@Override
public E first() {
throw new NoSuchElementException();
}
@Override
public E last() {
throw new NoSuchElementException();
}
......@@ -3328,7 +3335,7 @@ public class Collections {
*
* @see #emptyList()
*/
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public static final List EMPTY_LIST = new EmptyList<>();
/**
......@@ -3402,7 +3409,7 @@ public class Collections {
* @see #emptyMap()
* @since 1.3
*/
@SuppressWarnings("unchecked")
@SuppressWarnings("rawtypes")
public static final Map EMPTY_MAP = new EmptyMap<>();
/**
......@@ -3685,6 +3692,7 @@ public class Collections {
return a;
}
@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) {
final int n = this.n;
if (a.length < n) {
......@@ -3731,6 +3739,7 @@ public class Collections {
* the <tt>Comparable</tt> interface.
* @see Comparable
*/
@SuppressWarnings("unchecked")
public static <T> Comparator<T> reverseOrder() {
return (Comparator<T>) ReverseComparator.REVERSE_ORDER;
}
......
......@@ -208,7 +208,7 @@ class ComparableTimSort {
* @param start the index of the first element in the range that is
* not already known to be sorted ({@code lo <= start <= hi})
*/
@SuppressWarnings({ "fallthrough", "rawtypes", "unchecked" })
@SuppressWarnings({"fallthrough", "rawtypes", "unchecked"})
private static void binarySort(Object[] a, int lo, int hi, int start) {
assert lo <= start && start <= hi;
if (start == lo)
......@@ -277,7 +277,7 @@ class ComparableTimSort {
* @return the length of the run beginning at the specified position in
* the specified array
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
private static int countRunAndMakeAscending(Object[] a, int lo, int hi) {
assert lo < hi;
int runHi = lo + 1;
......@@ -612,7 +612,7 @@ class ComparableTimSort {
* (must be aBase + aLen)
* @param len2 length of second run to be merged (must be > 0)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
private void mergeLo(int base1, int len1, int base2, int len2) {
assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
......@@ -729,7 +729,7 @@ class ComparableTimSort {
* (must be aBase + aLen)
* @param len2 length of second run to be merged (must be > 0)
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
@SuppressWarnings({"unchecked", "rawtypes"})
private void mergeHi(int base1, int len1, int base2, int len2) {
assert len1 > 0 && len2 > 0 && base1 + len1 == base2;
......
/*
* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2012, 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
......@@ -230,7 +230,7 @@ public class HashMap<K,V>
this.loadFactor = loadFactor;
threshold = (int)Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1);
table = new Entry[capacity];
table = new Entry<?,?>[capacity];
init();
}
......@@ -1078,7 +1078,7 @@ public class HashMap<K,V>
capacity <<= 1;
}
table = new Entry[capacity];
table = new Entry<?,?>[capacity];
threshold = (int) Math.min(capacity * loadFactor, MAXIMUM_CAPACITY + 1);
init(); // Give subclass a chance to do its thing.
......
/*
* Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2012, 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
......@@ -121,6 +121,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
unseen = elements[0];
}
@Override
public boolean hasNext() {
while (unseen == 0 && unseenIndex < elements.length - 1)
unseen = elements[++unseenIndex];
......@@ -128,6 +129,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
}
@Override
@SuppressWarnings("unchecked")
public E next() {
if (!hasNext())
throw new NoSuchElementException();
......@@ -138,6 +140,7 @@ class JumboEnumSet<E extends Enum<E>> extends EnumSet<E> {
+ Long.numberOfTrailingZeros(lastReturned)];
}
@Override
public void remove() {
if (lastReturned == 0)
throw new IllegalStateException();
......
/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2012, 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
......@@ -330,6 +330,7 @@ public class PriorityQueue<E> extends AbstractQueue<E>
return true;
}
@SuppressWarnings("unchecked")
public E peek() {
if (size == 0)
return null;
......
......@@ -246,7 +246,8 @@ public final class PropertyPermission extends BasicPermission {
return mask;
}
// Check against use of constants (used heavily within the JDK)
// Use object identity comparison against known-interned strings for
// performance benefit (these values are used heavily within the JDK).
if (actions == SecurityConstants.PROPERTY_READ_ACTION) {
return READ;
} if (actions == SecurityConstants.PROPERTY_WRITE_ACTION) {
......
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2012, 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
......@@ -125,6 +125,7 @@ public class PropertyResourceBundle extends ResourceBundle {
* @throws IOException if an I/O error occurs
* @throws NullPointerException if <code>stream</code> is null
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public PropertyResourceBundle (InputStream stream) throws IOException {
Properties properties = new Properties();
properties.load(stream);
......@@ -143,6 +144,7 @@ public class PropertyResourceBundle extends ResourceBundle {
* @throws NullPointerException if <code>reader</code> is null
* @since 1.6
*/
@SuppressWarnings({"unchecked", "rawtypes"})
public PropertyResourceBundle (Reader reader) throws IOException {
Properties properties = new Properties();
properties.load(reader);
......
/*
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2012, 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
......@@ -325,6 +325,7 @@ class JarVerifier {
* the given file in the jar.
* @deprecated
*/
@Deprecated
public java.security.cert.Certificate[] getCerts(String name)
{
return mapSignersToCertArray(getCodeSigners(name));
......
/*
* Copyright (c) 2003,2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003,2012, 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
......@@ -726,13 +726,13 @@ public abstract class Pack200 {
private static final String PACK_PROVIDER = "java.util.jar.Pack200.Packer";
private static final String UNPACK_PROVIDER = "java.util.jar.Pack200.Unpacker";
private static Class packerImpl;
private static Class unpackerImpl;
private static Class<?> packerImpl;
private static Class<?> unpackerImpl;
private synchronized static Object newInstance(String prop) {
String implName = "(unknown)";
try {
Class impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
Class<?> impl = (PACK_PROVIDER.equals(prop))? packerImpl: unpackerImpl;
if (impl == null) {
// The first time, we must decide which class to use.
implName = java.security.AccessController.doPrivileged(
......
......@@ -126,7 +126,7 @@ public abstract class PreHashedMap<V>
*/
protected abstract void init(Object[] ht);
// @SuppressWarnings("unchecked")
@SuppressWarnings("unchecked")
private V toV(Object x) {
return (V)x;
}
......@@ -259,8 +259,7 @@ public abstract class PreHashedMap<V>
return true;
if (!(ob instanceof Map.Entry))
return false;
Map.Entry<String,V> that
= (Map.Entry<String,V>)ob;
Map.Entry<?,?> that = (Map.Entry<?,?>)ob;
return ((this.getKey() == null
? that.getKey() == null
: this.getKey()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册