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

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
This commit is contained in:
Dan Xu 2012-08-31 13:42:47 -07:00
parent 366a5c5175
commit b6bee3c9e9
19 changed files with 72 additions and 53 deletions

View File

@ -1,5 +1,5 @@
/*
* 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);

View File

@ -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;

View File

@ -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)

View File

@ -1,5 +1,5 @@
/*
* 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
@ -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);
}

View File

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

View File

@ -1,5 +1,5 @@
/*
* 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.

View File

@ -1,5 +1,5 @@
/*
* 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();

View File

@ -1,5 +1,5 @@
/*
* 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;

View File

@ -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) {

View File

@ -1,5 +1,5 @@
/*
* 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);

View File

@ -1,5 +1,5 @@
/*
* 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));

View File

@ -1,5 +1,5 @@
/*
* 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(

View File

@ -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()