diff --git a/make/common/Defs-linux.gmk b/make/common/Defs-linux.gmk index 9d403b115384dcd7e77a15350ccc4930be56b39f..a0bfc3cc8d3ffabe88bea430df78dbeb479893a8 100644 --- a/make/common/Defs-linux.gmk +++ b/make/common/Defs-linux.gmk @@ -157,9 +157,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) _JUNK_ := $(shell \ echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)") - # HACK: disable ZIP_DEBUGINFO_FILES by default until install repo - # changes are promoted - ZIP_DEBUGINFO_FILES ?= 0 + ZIP_DEBUGINFO_FILES ?= 1 _JUNK_ := $(shell \ echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)") diff --git a/make/common/Defs-solaris.gmk b/make/common/Defs-solaris.gmk index ad445e978483c8b65d42ddad0202aaac0ed26461..5c272be1c35842df452dc360a9f10258fbac1914 100644 --- a/make/common/Defs-solaris.gmk +++ b/make/common/Defs-solaris.gmk @@ -165,9 +165,7 @@ ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) _JUNK_ := $(shell \ echo >&2 "INFO: STRIP_POLICY=$(STRIP_POLICY)") - # HACK: disable ZIP_DEBUGINFO_FILES by default until install repo - # changes are promoted - ZIP_DEBUGINFO_FILES ?= 0 + ZIP_DEBUGINFO_FILES ?= 1 _JUNK_ := $(shell \ echo >&2 "INFO: ZIP_DEBUGINFO_FILES=$(ZIP_DEBUGINFO_FILES)") diff --git a/make/common/Defs-windows.gmk b/make/common/Defs-windows.gmk index 3d1ec781bf5a9d6185ca348d18316bd28dac00b6..7afe0b515e079f8b91a27e02d542bb709147645f 100644 --- a/make/common/Defs-windows.gmk +++ b/make/common/Defs-windows.gmk @@ -113,9 +113,7 @@ _JUNK_ := $(shell \ echo >&2 "INFO: ENABLE_FULL_DEBUG_SYMBOLS=$(ENABLE_FULL_DEBUG_SYMBOLS)") ifeq ($(ENABLE_FULL_DEBUG_SYMBOLS),1) - # HACK: disable ZIP_DEBUGINFO_FILES by default until install repo - # changes are promoted - ZIP_DEBUGINFO_FILES ?= 0 + ZIP_DEBUGINFO_FILES ?= 1 else ZIP_DEBUGINFO_FILES=0 endif diff --git a/src/share/classes/java/net/HttpCookie.java b/src/share/classes/java/net/HttpCookie.java index bb12564193d9c7ede6dafe2d40040331372d5b8d..1963e1fc9138fcd7d665831d8158edd00b81dd10 100644 --- a/src/share/classes/java/net/HttpCookie.java +++ b/src/share/classes/java/net/HttpCookie.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2005, 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 @@ -616,9 +616,6 @@ public final class HttpCookie implements Cloneable { * would be accepted. *
  • A Set-Cookie2 with Domain=.com or Domain=.com., will always be * rejected, because there is no embedded dot.
  • - *
  • A Set-Cookie2 with Domain=ajax.com will be accepted, and the - * value for Domain will be taken to be .ajax.com, because a dot - * gets prepended to the value.
  • *
  • A Set-Cookie2 from request-host example for Domain=.local will * be accepted, because the effective host name for the request- * host is example.local, and example.local domain-matches .local.
  • diff --git a/src/share/classes/java/nio/file/Path.java b/src/share/classes/java/nio/file/Path.java index 92cd1f9661ea0fd9878819e4bfd2149fb0d39237..afe07a387d6e37e84024fb3b7f47406688720bae 100644 --- a/src/share/classes/java/nio/file/Path.java +++ b/src/share/classes/java/nio/file/Path.java @@ -54,7 +54,7 @@ import java.util.Iterator; * resolveSibling} methods to combine paths. The {@link #relativize relativize} * method that can be used to construct a relative path between two paths. * Paths can be {@link #compareTo compared}, and tested against each other using - * the {@link #startsWith startsWith} and {@link #endsWith endWith} methods. + * the {@link #startsWith startsWith} and {@link #endsWith endsWith} methods. * *

    This interface extends {@link Watchable} interface so that a directory * located by a path can be {@link #register registered} with a {@link diff --git a/src/share/classes/java/util/AbstractCollection.java b/src/share/classes/java/util/AbstractCollection.java index a32d41156a3912b0b239546038b8b075db63bab2..3824f390463651804183ff181d368dab03f7ef04 100644 --- a/src/share/classes/java/util/AbstractCollection.java +++ b/src/share/classes/java/util/AbstractCollection.java @@ -170,6 +170,7 @@ public abstract class AbstractCollection implements Collection { * @throws ArrayStoreException {@inheritDoc} * @throws NullPointerException {@inheritDoc} */ + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { // Estimate size of array; be prepared to see more or fewer elements int size = size(); @@ -216,6 +217,7 @@ public abstract class AbstractCollection implements Collection { * @return array containing the elements in the given array, plus any * further elements returned by the iterator, trimmed to size */ + @SuppressWarnings("unchecked") private static T[] finishToArray(T[] r, Iterator it) { int i = r.length; while (it.hasNext()) { diff --git a/src/share/classes/java/util/AbstractList.java b/src/share/classes/java/util/AbstractList.java index 4492166111b008ac69143c3272f1ac2132c17476..0b605150679970755b57384ddacc9f8e7de4815a 100644 --- a/src/share/classes/java/util/AbstractList.java +++ b/src/share/classes/java/util/AbstractList.java @@ -516,7 +516,7 @@ public abstract class AbstractList extends AbstractCollection implements L return false; ListIterator e1 = listIterator(); - ListIterator e2 = ((List) o).listIterator(); + ListIterator e2 = ((List) o).listIterator(); while (e1.hasNext() && e2.hasNext()) { E o1 = e1.next(); Object o2 = e2.next(); diff --git a/src/share/classes/java/util/AbstractMap.java b/src/share/classes/java/util/AbstractMap.java index a3ad3d3497a28b4e159ee67137b17830a06df258..aba5048becdac5767dadd1353b66391f95f7ef28 100644 --- a/src/share/classes/java/util/AbstractMap.java +++ b/src/share/classes/java/util/AbstractMap.java @@ -443,7 +443,7 @@ public abstract class AbstractMap implements Map { if (!(o instanceof Map)) return false; - Map m = (Map) o; + Map m = (Map) o; if (m.size() != size()) return false; @@ -534,7 +534,7 @@ public abstract class AbstractMap implements Map { * @return a shallow copy of this map */ protected Object clone() throws CloneNotSupportedException { - AbstractMap result = (AbstractMap)super.clone(); + AbstractMap result = (AbstractMap)super.clone(); result.keySet = null; result.values = null; return result; @@ -652,7 +652,7 @@ public abstract class AbstractMap implements Map { public boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry)o; return eq(key, e.getKey()) && eq(value, e.getValue()); } @@ -783,7 +783,7 @@ public abstract class AbstractMap implements Map { public boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry)o; return eq(key, e.getKey()) && eq(value, e.getValue()); } diff --git a/src/share/classes/java/util/AbstractSet.java b/src/share/classes/java/util/AbstractSet.java index 1f1a49c250e4cdf058c12cdaaca3499c195baeb6..03e45ba38c0e412dd8988c759e0156b27a934224 100644 --- a/src/share/classes/java/util/AbstractSet.java +++ b/src/share/classes/java/util/AbstractSet.java @@ -88,7 +88,7 @@ public abstract class AbstractSet extends AbstractCollection implements Se if (!(o instanceof Set)) return false; - Collection c = (Collection) o; + Collection c = (Collection) o; if (c.size() != size()) return false; try { diff --git a/src/share/classes/java/util/ArrayDeque.java b/src/share/classes/java/util/ArrayDeque.java index eb70aaa59ccbb04371d8546c4016fc76bb64dee8..8a9a0ee7b8b16665353d25581d28ba17efbf412f 100644 --- a/src/share/classes/java/util/ArrayDeque.java +++ b/src/share/classes/java/util/ArrayDeque.java @@ -813,7 +813,8 @@ public class ArrayDeque extends AbstractCollection */ public ArrayDeque clone() { try { - ArrayDeque result = (ArrayDeque) super.clone(); + @SuppressWarnings("unchecked") + ArrayDeque result = (ArrayDeque) super.clone(); result.elements = Arrays.copyOf(elements, elements.length); return result; @@ -849,6 +850,7 @@ public class ArrayDeque extends AbstractCollection /** * Deserialize this deque. */ + @SuppressWarnings("unchecked") private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException { s.defaultReadObject(); diff --git a/src/share/classes/java/util/ArrayList.java b/src/share/classes/java/util/ArrayList.java index 3b029272753ed2e7d8c83f26f915698cd862f7b4..eb44bd959eea359e18b9457e6e9c99da522b76e7 100644 --- a/src/share/classes/java/util/ArrayList.java +++ b/src/share/classes/java/util/ArrayList.java @@ -300,8 +300,7 @@ public class ArrayList extends AbstractList */ public Object clone() { try { - @SuppressWarnings("unchecked") - ArrayList v = (ArrayList) super.clone(); + ArrayList v = (ArrayList) super.clone(); v.elementData = Arrays.copyOf(elementData, size); v.modCount = 0; return v; diff --git a/src/share/classes/java/util/Arrays.java b/src/share/classes/java/util/Arrays.java index fd408e27b60ccdb4abcb13c78557a187f00c9b08..d0c3a60a05a41f50982c1871112d27657cf0b196 100644 --- a/src/share/classes/java/util/Arrays.java +++ b/src/share/classes/java/util/Arrays.java @@ -560,6 +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" }) private static void mergeSort(Object[] src, Object[] dest, int low, @@ -746,6 +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" }) private static void mergeSort(Object[] src, Object[] dest, int low, int high, int off, @@ -1477,8 +1479,10 @@ public class Arrays { while (low <= high) { int mid = (low + high) >>> 1; - Comparable midVal = (Comparable)a[mid]; - int cmp = midVal.compareTo(key); + @SuppressWarnings("rawtypes") + Comparable midVal = (Comparable)a[mid]; + @SuppressWarnings("unchecked") + int cmp = midVal.compareTo(key); if (cmp < 0) low = mid + 1; @@ -2215,6 +2219,7 @@ public class Arrays { * @throws NullPointerException if original is null * @since 1.6 */ + @SuppressWarnings("unchecked") public static T[] copyOf(T[] original, int newLength) { return (T[]) copyOf(original, newLength, original.getClass()); } @@ -2242,6 +2247,7 @@ public class Arrays { * @since 1.6 */ public static T[] copyOf(U[] original, int newLength, Class newType) { + @SuppressWarnings("unchecked") T[] copy = ((Object)newType == (Object)Object[].class) ? (T[]) new Object[newLength] : (T[]) Array.newInstance(newType.getComponentType(), newLength); @@ -2470,8 +2476,9 @@ public class Arrays { * @throws NullPointerException if original is null * @since 1.6 */ + @SuppressWarnings("unchecked") public static T[] copyOfRange(T[] original, int from, int to) { - return copyOfRange(original, from, to, (Class) original.getClass()); + return copyOfRange(original, from, to, (Class) original.getClass()); } /** @@ -2509,6 +2516,7 @@ public class Arrays { int newLength = to - from; if (newLength < 0) throw new IllegalArgumentException(from + " > " + to); + @SuppressWarnings("unchecked") T[] copy = ((Object)newType == (Object)Object[].class) ? (T[]) new Object[newLength] : (T[]) Array.newInstance(newType.getComponentType(), newLength); @@ -2851,6 +2859,7 @@ public class Arrays { return a.clone(); } + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { int size = size(); if (a.length < size) @@ -3634,7 +3643,7 @@ public class Arrays { if (element == null) { buf.append("null"); } else { - Class eClass = element.getClass(); + Class eClass = element.getClass(); if (eClass.isArray()) { if (eClass == byte[].class) diff --git a/src/share/classes/java/util/Calendar.java b/src/share/classes/java/util/Calendar.java index 21de73437a4d226cc6eaecf53055e6d7b7a02da4..0e04b22fab3c629d35dceeab4194e2d52978aad4 100644 --- a/src/share/classes/java/util/Calendar.java +++ b/src/share/classes/java/util/Calendar.java @@ -840,7 +840,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable cachedLocaleData - = new ConcurrentHashMap(3); + = new ConcurrentHashMap<>(3); // Special values of stamp[] /** @@ -1499,7 +1499,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable names = new HashMap(); + Map names = new HashMap<>(); for (int i = 0; i < strings.length; i++) { if (strings[i].length() == 0) { continue; diff --git a/src/share/classes/java/util/Collections.java b/src/share/classes/java/util/Collections.java index d18d568233698ab9239fb4ead6034f1b1d1abc5b..533260326809ccf919f30c0c31eff90a20db657c 100644 --- a/src/share/classes/java/util/Collections.java +++ b/src/share/classes/java/util/Collections.java @@ -150,6 +150,7 @@ public class Collections { * detects that the natural ordering of the list elements is * found to violate the {@link Comparable} contract */ + @SuppressWarnings("unchecked") public static > void sort(List list) { Object[] a = list.toArray(); Arrays.sort(a); @@ -212,13 +213,14 @@ public class Collections { * @throws IllegalArgumentException (optional) if the comparator is * found to violate the {@link Comparator} contract */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static void sort(List list, Comparator c) { Object[] a = list.toArray(); Arrays.sort(a, (Comparator)c); - ListIterator i = list.listIterator(); + ListIterator i = list.listIterator(); for (int j=0; j int binarySearch(List list, T key, Comparator c) { if (c==null) - return binarySearch((List) list, key); + return binarySearch((List>) list, key); if (list instanceof RandomAccess || list.size() {} - - /** * Reverses the order of the elements in the specified list.

    * @@ -418,12 +418,16 @@ public class Collections { * @throws UnsupportedOperationException if the specified list or * its list-iterator does not support the set operation. */ + @SuppressWarnings({ "rawtypes", "unchecked" }) public static void reverse(List list) { int size = list.size(); if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) { for (int i=0, mid=size>>1, j=size-1; i>1; iset operation. */ + @SuppressWarnings({ "rawtypes", "unchecked" }) public static void shuffle(List list, Random rnd) { int size = list.size(); if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) { @@ -506,6 +511,9 @@ public class Collections { swap(arr, i-1, rnd.nextInt(i)); // Dump array back into list + // instead of using a raw type here, it's possible to capture + // the wildcard but it will require a call to a supplementary + // private method ListIterator it = list.listIterator(); for (int i=0; i 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 + // private method final List l = list; l.set(i, l.set(j, l.get(i))); } @@ -657,9 +669,10 @@ public class Collections { * @throws NoSuchElementException if the collection is empty. * @see Comparable */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static T min(Collection coll, Comparator comp) { if (comp==null) - return (T)min((Collection) (Collection) coll); + return (T)min((Collection) coll); Iterator i = coll.iterator(); T candidate = i.next(); @@ -727,9 +740,10 @@ public class Collections { * @throws NoSuchElementException if the collection is empty. * @see Comparable */ + @SuppressWarnings({ "unchecked", "rawtypes" }) public static T max(Collection coll, Comparator comp) { if (comp==null) - return (T)max((Collection) (Collection) coll); + return (T)max((Collection) coll); Iterator i = coll.iterator(); T candidate = i.next(); @@ -1389,7 +1403,9 @@ public class Collections { extends UnmodifiableSet> { private static final long serialVersionUID = 7854390611657943733L; + @SuppressWarnings({ "unchecked", "rawtypes" }) UnmodifiableEntrySet(Set> s) { + // Need to cast to raw in order to work around a limitation in the type system super((Set)s); } public Iterator> iterator() { @@ -1408,13 +1424,15 @@ public class Collections { }; } + @SuppressWarnings("unchecked") public Object[] toArray() { Object[] a = c.toArray(); for (int i=0; i((Map.Entry)a[i]); + a[i] = new UnmodifiableEntry<>((Map.Entry)a[i]); return a; } + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { // We don't pass a to c.toArray, to avoid window of // vulnerability wherein an unscrupulous multithreaded client @@ -1422,7 +1440,7 @@ public class Collections { Object[] arr = c.toArray(a.length==0 ? a : Arrays.copyOf(a, 0)); for (int i=0; i((Map.Entry)arr[i]); + arr[i] = new UnmodifiableEntry<>((Map.Entry)arr[i]); if (arr.length > a.length) return (T[])arr; @@ -1464,7 +1482,7 @@ public class Collections { if (!(o instanceof Set)) return false; - Set s = (Set) o; + Set s = (Set) o; if (s.size() != c.size()) return false; return containsAll(s); // Invokes safe containsAll() above @@ -1493,7 +1511,7 @@ public class Collections { return true; if (!(o instanceof Map.Entry)) return false; - Map.Entry t = (Map.Entry)o; + Map.Entry t = (Map.Entry)o; return eq(e.getKey(), t.getKey()) && eq(e.getValue(), t.getValue()); } diff --git a/src/share/classes/java/util/ComparableTimSort.java b/src/share/classes/java/util/ComparableTimSort.java index 22427a2d353cba980b6a23d36d3f4b895cdbccd1..ae1ab6a1e817b30e5b3c2d324160cb76076802d2 100644 --- a/src/share/classes/java/util/ComparableTimSort.java +++ b/src/share/classes/java/util/ComparableTimSort.java @@ -114,7 +114,6 @@ class ComparableTimSort { // Allocate temp storage (which may be increased later if necessary) int len = a.length; - @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) Object[] newArray = new Object[len < 2 * INITIAL_TMP_STORAGE_LENGTH ? len >>> 1 : INITIAL_TMP_STORAGE_LENGTH]; tmp = newArray; @@ -209,14 +208,13 @@ 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") + @SuppressWarnings({ "fallthrough", "rawtypes", "unchecked" }) private static void binarySort(Object[] a, int lo, int hi, int start) { assert lo <= start && start <= hi; if (start == lo) start++; for ( ; start < hi; start++) { - @SuppressWarnings("unchecked") - Comparable pivot = (Comparable) a[start]; + Comparable pivot = (Comparable) a[start]; // Set left (and right) to the index where a[start] (pivot) belongs int left = lo; @@ -279,7 +277,7 @@ class ComparableTimSort { * @return the length of the run beginning at the specified position in * the specified array */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private static int countRunAndMakeAscending(Object[] a, int lo, int hi) { assert lo < hi; int runHi = lo + 1; @@ -614,7 +612,7 @@ class ComparableTimSort { * (must be aBase + aLen) * @param len2 length of second run to be merged (must be > 0) */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private void mergeLo(int base1, int len1, int base2, int len2) { assert len1 > 0 && len2 > 0 && base1 + len1 == base2; @@ -731,7 +729,7 @@ class ComparableTimSort { * (must be aBase + aLen) * @param len2 length of second run to be merged (must be > 0) */ - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) private void mergeHi(int base1, int len1, int base2, int len2) { assert len1 > 0 && len2 > 0 && base1 + len1 == base2; @@ -865,7 +863,6 @@ class ComparableTimSort { else newSize = Math.min(newSize, a.length >>> 1); - @SuppressWarnings({"unchecked", "UnnecessaryLocalVariable"}) Object[] newArray = new Object[newSize]; tmp = newArray; } diff --git a/src/share/classes/java/util/Currency.java b/src/share/classes/java/util/Currency.java index ad241c8ee2705c451821f53e491e781eae213f02..1fbdad42cb99958c8d2e1134ce7c846aa982a055 100644 --- a/src/share/classes/java/util/Currency.java +++ b/src/share/classes/java/util/Currency.java @@ -404,7 +404,7 @@ public final class Currency implements Serializable { public static Set getAvailableCurrencies() { synchronized(Currency.class) { if (available == null) { - available = new HashSet(256); + available = new HashSet<>(256); // Add simple currencies first for (char c1 = 'A'; c1 <= 'Z'; c1 ++) { diff --git a/src/share/classes/java/util/EnumMap.java b/src/share/classes/java/util/EnumMap.java index a7c248f6167fae7ad46b38c5c57fbb69907883b4..90046abcfa6d0944995b7f080ca128bb8e62f3e5 100644 --- a/src/share/classes/java/util/EnumMap.java +++ b/src/share/classes/java/util/EnumMap.java @@ -120,11 +120,12 @@ public class EnumMap, V> extends AbstractMap return (value == null ? NULL : value); } + @SuppressWarnings("unchecked") private V unmaskNull(Object value) { - return (V) (value == NULL ? null : value); + return (V)(value == NULL ? null : value); } - private static final Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0]; + private static final Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0]; /** * Creates an empty enum map with the specified key type. @@ -218,12 +219,12 @@ public class EnumMap, V> extends AbstractMap * key */ public boolean containsKey(Object key) { - return isValidKey(key) && vals[((Enum)key).ordinal()] != null; + return isValidKey(key) && vals[((Enum)key).ordinal()] != null; } private boolean containsMapping(Object key, Object value) { return isValidKey(key) && - maskNull(value).equals(vals[((Enum)key).ordinal()]); + maskNull(value).equals(vals[((Enum)key).ordinal()]); } /** @@ -243,7 +244,7 @@ public class EnumMap, V> extends AbstractMap */ public V get(Object key) { return (isValidKey(key) ? - unmaskNull(vals[((Enum)key).ordinal()]) : null); + unmaskNull(vals[((Enum)key).ordinal()]) : null); } // Modification Operations @@ -285,7 +286,7 @@ public class EnumMap, V> extends AbstractMap public V remove(Object key) { if (!isValidKey(key)) return null; - int index = ((Enum)key).ordinal(); + int index = ((Enum)key).ordinal(); Object oldValue = vals[index]; vals[index] = null; if (oldValue != null) @@ -296,7 +297,7 @@ public class EnumMap, V> extends AbstractMap private boolean removeMapping(Object key, Object value) { if (!isValidKey(key)) return false; - int index = ((Enum)key).ordinal(); + int index = ((Enum)key).ordinal(); if (maskNull(value).equals(vals[index])) { vals[index] = null; size--; @@ -314,7 +315,7 @@ public class EnumMap, V> extends AbstractMap return false; // Cheaper than instanceof Enum followed by getDeclaringClass - Class keyClass = key.getClass(); + Class keyClass = key.getClass(); return keyClass == keyType || keyClass.getSuperclass() == keyType; } @@ -331,8 +332,7 @@ public class EnumMap, V> extends AbstractMap */ public void putAll(Map m) { if (m instanceof EnumMap) { - EnumMap em = - (EnumMap)m; + EnumMap em = (EnumMap)m; if (em.keyType != keyType) { if (em.isEmpty()) return; @@ -476,13 +476,13 @@ public class EnumMap, V> extends AbstractMap public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry)o; + Map.Entry entry = (Map.Entry)o; return containsMapping(entry.getKey(), entry.getValue()); } public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry)o; + Map.Entry entry = (Map.Entry)o; return removeMapping(entry.getKey(), entry.getValue()); } public int size() { @@ -610,7 +610,7 @@ public class EnumMap, V> extends AbstractMap if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry)o; V ourValue = unmaskNull(vals[index]); Object hisValue = e.getValue(); return (e.getKey() == keyUniverse[index] && @@ -655,11 +655,11 @@ public class EnumMap, V> extends AbstractMap if (this == o) return true; if (o instanceof EnumMap) - return equals((EnumMap)o); + return equals((EnumMap)o); if (!(o instanceof Map)) return false; - Map m = (Map)o; + Map m = (Map)o; if (size != m.size()) return false; @@ -680,7 +680,7 @@ public class EnumMap, V> extends AbstractMap return true; } - private boolean equals(EnumMap em) { + private boolean equals(EnumMap em) { if (em.keyType != keyType) return size == 0 && em.size == 0; @@ -721,6 +721,7 @@ public class EnumMap, V> extends AbstractMap * * @return a shallow copy of this enum map */ + @SuppressWarnings("unchecked") public EnumMap clone() { EnumMap result = null; try { @@ -736,7 +737,7 @@ public class EnumMap, V> extends AbstractMap * Throws an exception if e is not of the correct type for this enum set. */ private void typeCheck(K key) { - Class keyClass = key.getClass(); + Class keyClass = key.getClass(); if (keyClass != keyType && keyClass.getSuperclass() != keyType) throw new ClassCastException(keyClass + " != " + keyType); } @@ -785,6 +786,7 @@ public class EnumMap, V> extends AbstractMap * Reconstitute the EnumMap instance from a stream (i.e., * deserialize it). */ + @SuppressWarnings("unchecked") private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { diff --git a/src/share/classes/java/util/EnumSet.java b/src/share/classes/java/util/EnumSet.java index 2c6a52ab907d6e9184bc6edac4815de4fb3aaa48..dab4bd73e1d52c9888b111ca49c7b6d2f2758c82 100644 --- a/src/share/classes/java/util/EnumSet.java +++ b/src/share/classes/java/util/EnumSet.java @@ -88,11 +88,11 @@ public abstract class EnumSet> extends AbstractSet /** * All of the values comprising T. (Cached for performance.) */ - final Enum[] universe; + final Enum[] universe; - private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0]; + private static Enum[] ZERO_LENGTH_ENUM_ARRAY = new Enum[0]; - EnumSet(ClasselementType, Enum[] universe) { + EnumSet(ClasselementType, Enum[] universe) { this.elementType = elementType; this.universe = universe; } @@ -105,7 +105,7 @@ public abstract class EnumSet> extends AbstractSet * @throws NullPointerException if elementType is null */ public static > EnumSet noneOf(Class elementType) { - Enum[] universe = getUniverse(elementType); + Enum[] universe = getUniverse(elementType); if (universe == null) throw new ClassCastException(elementType + " not an enum"); @@ -358,6 +358,7 @@ public abstract class EnumSet> extends AbstractSet * * @return a copy of this set */ + @SuppressWarnings("unchecked") public EnumSet clone() { try { return (EnumSet) super.clone(); @@ -375,7 +376,7 @@ public abstract class EnumSet> extends AbstractSet * Throws an exception if e is not of the correct type for this enum set. */ final void typeCheck(E e) { - Class eClass = e.getClass(); + Class eClass = e.getClass(); if (eClass != elementType && eClass.getSuperclass() != elementType) throw new ClassCastException(eClass + " != " + elementType); } @@ -413,16 +414,19 @@ public abstract class EnumSet> extends AbstractSet * * @serial */ - private final Enum[] elements; + private final Enum[] elements; SerializationProxy(EnumSet set) { elementType = set.elementType; elements = set.toArray(ZERO_LENGTH_ENUM_ARRAY); } + // instead of cast to E, we should perhaps use elementType.cast() + // to avoid injection of forged stream, but it will slow the implementation + @SuppressWarnings("unchecked") private Object readResolve() { EnumSet result = EnumSet.noneOf(elementType); - for (Enum e : elements) + for (Enum e : elements) result.add((E)e); return result; } diff --git a/src/share/classes/java/util/HashMap.java b/src/share/classes/java/util/HashMap.java index 916d6951ec28cb882ea12f5dc8c7d1a8995e7bf7..efc707fa28c3e3847e090d9348122128063b7316 100644 --- a/src/share/classes/java/util/HashMap.java +++ b/src/share/classes/java/util/HashMap.java @@ -146,7 +146,7 @@ public class HashMap /** * The table, resized as necessary. Length MUST Always be a power of two. */ - transient Entry[] table; + transient Entry[] table; /** * The number of key-value mappings contained in this map. @@ -311,16 +311,17 @@ public class HashMap * * @see #put(Object, Object) */ + @SuppressWarnings("unchecked") public V get(Object key) { if (key == null) - return getForNullKey(); + return (V)getForNullKey(); int hash = hash(key.hashCode()); - for (Entry e = table[indexFor(hash, table.length)]; + for (Entry e = table[indexFor(hash, table.length)]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) - return e.value; + return (V)e.value; } return null; } @@ -332,8 +333,8 @@ public class HashMap * operations (get and put), but incorporated with conditionals in * others. */ - private V getForNullKey() { - for (Entry e = table[0]; e != null; e = e.next) { + private Object getForNullKey() { + for (Entry e = table[0]; e != null; e = e.next) { if (e.key == null) return e.value; } @@ -357,15 +358,16 @@ public class HashMap * HashMap. Returns null if the HashMap contains no mapping * for the key. */ + @SuppressWarnings("unchecked") final Entry getEntry(Object key) { int hash = (key == null) ? 0 : hash(key.hashCode()); - for (Entry e = table[indexFor(hash, table.length)]; + for (Entry e = table[indexFor(hash, table.length)]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || (key != null && key.equals(k)))) - return e; + return (Entry)e; } return null; } @@ -388,7 +390,9 @@ public class HashMap return putForNullKey(value); int hash = hash(key.hashCode()); int i = indexFor(hash, table.length); - for (Entry e = table[i]; e != null; e = e.next) { + @SuppressWarnings("unchecked") + Entry e = (Entry)table[i]; + for(; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || key.equals(k))) { V oldValue = e.value; @@ -407,7 +411,9 @@ public class HashMap * Offloaded version of put for null keys */ private V putForNullKey(V value) { - for (Entry e = table[0]; e != null; e = e.next) { + @SuppressWarnings("unchecked") + Entry e = (Entry)table[0]; + for(; e != null; e = e.next) { if (e.key == null) { V oldValue = e.value; e.value = value; @@ -435,7 +441,8 @@ public class HashMap * clone or deserialize. It will only happen for construction if the * input Map is a sorted map whose ordering is inconsistent w/ equals. */ - for (Entry e = table[i]; e != null; e = e.next) { + for (@SuppressWarnings("unchecked") + Entry e = (Entry)table[i]; e != null; e = e.next) { Object k; if (e.hash == hash && ((k = e.key) == key || (key != null && key.equals(k)))) { @@ -467,14 +474,14 @@ public class HashMap * is irrelevant). */ void resize(int newCapacity) { - Entry[] oldTable = table; + Entry[] oldTable = table; int oldCapacity = oldTable.length; if (oldCapacity == MAXIMUM_CAPACITY) { threshold = Integer.MAX_VALUE; return; } - Entry[] newTable = new Entry[newCapacity]; + Entry[] newTable = new Entry[newCapacity]; transfer(newTable); table = newTable; threshold = (int)(newCapacity * loadFactor); @@ -483,17 +490,18 @@ public class HashMap /** * Transfers all entries from current table to newTable. */ - void transfer(Entry[] newTable) { - Entry[] src = table; + @SuppressWarnings("unchecked") + void transfer(Entry[] newTable) { + Entry[] src = table; int newCapacity = newTable.length; for (int j = 0; j < src.length; j++) { - Entry e = src[j]; + Entry e = (Entry)src[j]; if (e != null) { src[j] = null; do { Entry next = e.next; int i = indexFor(e.hash, newCapacity); - e.next = newTable[i]; + e.next = (Entry)newTable[i]; newTable[i] = e; e = next; } while (e != null); @@ -560,7 +568,8 @@ public class HashMap final Entry removeEntryForKey(Object key) { int hash = (key == null) ? 0 : hash(key.hashCode()); int i = indexFor(hash, table.length); - Entry prev = table[i]; + @SuppressWarnings("unchecked") + Entry prev = (Entry)table[i]; Entry e = prev; while (e != null) { @@ -591,11 +600,12 @@ public class HashMap if (!(o instanceof Map.Entry)) return null; - Map.Entry entry = (Map.Entry) o; + Map.Entry entry = (Map.Entry) o; Object key = entry.getKey(); int hash = (key == null) ? 0 : hash(key.hashCode()); int i = indexFor(hash, table.length); - Entry prev = table[i]; + @SuppressWarnings("unchecked") + Entry prev = (Entry)table[i]; Entry e = prev; while (e != null) { @@ -623,7 +633,7 @@ public class HashMap */ public void clear() { modCount++; - Entry[] tab = table; + Entry[] tab = table; for (int i = 0; i < tab.length; i++) tab[i] = null; size = 0; @@ -641,9 +651,9 @@ public class HashMap if (value == null) return containsNullValue(); - Entry[] tab = table; + Entry[] tab = table; for (int i = 0; i < tab.length ; i++) - for (Entry e = tab[i] ; e != null ; e = e.next) + for (Entry e = tab[i] ; e != null ; e = e.next) if (value.equals(e.value)) return true; return false; @@ -653,9 +663,9 @@ public class HashMap * Special-case code for containsValue with null argument */ private boolean containsNullValue() { - Entry[] tab = table; + Entry[] tab = table; for (int i = 0; i < tab.length ; i++) - for (Entry e = tab[i] ; e != null ; e = e.next) + for (Entry e = tab[i] ; e != null ; e = e.next) if (e.value == null) return true; return false; @@ -667,6 +677,7 @@ public class HashMap * * @return a shallow copy of this map */ + @SuppressWarnings("unchecked") public Object clone() { HashMap result = null; try { @@ -674,7 +685,7 @@ public class HashMap } catch (CloneNotSupportedException e) { // assert false; } - result.table = new Entry[table.length]; + result.table = new Entry[table.length]; result.entrySet = null; result.modCount = 0; result.size = 0; @@ -717,7 +728,7 @@ public class HashMap public final boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry)o; Object k1 = getKey(); Object k2 = e.getKey(); if (k1 == k2 || (k1 != null && k1.equals(k2))) { @@ -762,7 +773,8 @@ public class HashMap * Subclass overrides this to alter the behavior of put method. */ void addEntry(int hash, K key, V value, int bucketIndex) { - Entry e = table[bucketIndex]; + @SuppressWarnings("unchecked") + Entry e = (Entry)table[bucketIndex]; table[bucketIndex] = new Entry<>(hash, key, value, e); if (size++ >= threshold) resize(2 * table.length); @@ -777,21 +789,22 @@ public class HashMap * clone, and readObject. */ void createEntry(int hash, K key, V value, int bucketIndex) { - Entry e = table[bucketIndex]; + @SuppressWarnings("unchecked") + Entry e = (Entry)table[bucketIndex]; table[bucketIndex] = new Entry<>(hash, key, value, e); size++; } private abstract class HashIterator implements Iterator { - Entry next; // next entry to return + Entry next; // next entry to return int expectedModCount; // For fast-fail int index; // current slot - Entry current; // current entry + Entry current; // current entry HashIterator() { expectedModCount = modCount; if (size > 0) { // advance to first entry - Entry[] t = table; + Entry[] t = table; while (index < t.length && (next = t[index++]) == null) ; } @@ -801,20 +814,21 @@ public class HashMap return next != null; } + @SuppressWarnings("unchecked") final Entry nextEntry() { if (modCount != expectedModCount) throw new ConcurrentModificationException(); - Entry e = next; + Entry e = next; if (e == null) throw new NoSuchElementException(); if ((next = e.next) == null) { - Entry[] t = table; + Entry[] t = table; while (index < t.length && (next = t[index++]) == null) ; } current = e; - return e; + return (Entry)e; } public void remove() { @@ -965,7 +979,7 @@ public class HashMap public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry) o; + Map.Entry e = (Map.Entry) o; Entry candidate = getEntry(e.getKey()); return candidate != null && candidate.equals(e); } @@ -1039,8 +1053,10 @@ public class HashMap // Read the keys and values, and put the mappings in the HashMap for (int i=0; i * * @return a shallow copy of this set */ + @SuppressWarnings("unchecked") public Object clone() { try { HashSet newSet = (HashSet) super.clone(); @@ -296,7 +297,7 @@ public class HashSet // Read in HashMap capacity and load factor and create backing HashMap int capacity = s.readInt(); float loadFactor = s.readFloat(); - map = (((HashSet)this) instanceof LinkedHashSet ? + map = (((HashSet)this) instanceof LinkedHashSet ? new LinkedHashMap(capacity, loadFactor) : new HashMap(capacity, loadFactor)); @@ -305,7 +306,8 @@ public class HashSet // Read in all elements in the proper order. for (int i=0; i /** * The hash table data. */ - private transient Entry[] table; + private transient Entry[] table; /** * The total number of entries in the hash table. @@ -182,7 +182,7 @@ public class Hashtable if (initialCapacity==0) initialCapacity = 1; this.loadFactor = loadFactor; - table = new Entry[initialCapacity]; + table = new Entry[initialCapacity]; threshold = (int)(initialCapacity * loadFactor); } @@ -288,9 +288,9 @@ public class Hashtable throw new NullPointerException(); } - Entry tab[] = table; + Entry tab[] = table; for (int i = tab.length ; i-- > 0 ;) { - for (Entry e = tab[i] ; e != null ; e = e.next) { + for (Entry e = tab[i] ; e != null ; e = e.next) { if (e.value.equals(value)) { return true; } @@ -326,10 +326,10 @@ public class Hashtable * @see #contains(Object) */ public synchronized boolean containsKey(Object key) { - Entry tab[] = table; + Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index] ; e != null ; e = e.next) { + for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { return true; } @@ -352,13 +352,14 @@ public class Hashtable * @throws NullPointerException if the specified key is null * @see #put(Object, Object) */ + @SuppressWarnings("unchecked") public synchronized V get(Object key) { - Entry tab[] = table; + Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index] ; e != null ; e = e.next) { + for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { - return e.value; + return (V)e.value; } } return null; @@ -379,9 +380,10 @@ public class Hashtable * number of keys in the hashtable exceeds this hashtable's capacity * and load factor. */ + @SuppressWarnings("unchecked") protected void rehash() { int oldCapacity = table.length; - Entry[] oldMap = table; + Entry[] oldMap = table; // overflow-conscious code int newCapacity = (oldCapacity << 1) + 1; @@ -391,19 +393,19 @@ public class Hashtable return; newCapacity = MAX_ARRAY_SIZE; } - Entry[] newMap = new Entry[newCapacity]; + Entry[] newMap = new Entry[newCapacity]; modCount++; threshold = (int)(newCapacity * loadFactor); table = newMap; for (int i = oldCapacity ; i-- > 0 ;) { - for (Entry old = oldMap[i] ; old != null ; ) { + for (Entry old = (Entry)oldMap[i] ; old != null ; ) { Entry e = old; old = old.next; int index = (e.hash & 0x7FFFFFFF) % newCapacity; - e.next = newMap[index]; + e.next = (Entry)newMap[index]; newMap[index] = e; } } @@ -433,13 +435,15 @@ public class Hashtable } // Makes sure the key is not already in the hashtable. - Entry tab[] = table; + Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index] ; e != null ; e = e.next) { - if ((e.hash == hash) && e.key.equals(key)) { - V old = e.value; - e.value = value; + @SuppressWarnings("unchecked") + Entry entry = (Entry)tab[index]; + for(; entry != null ; entry = entry.next) { + if ((entry.hash == hash) && entry.key.equals(key)) { + V old = entry.value; + entry.value = value; return old; } } @@ -454,7 +458,8 @@ public class Hashtable } // Creates the new entry. - Entry e = tab[index]; + @SuppressWarnings("unchecked") + Entry e = (Entry)tab[index]; tab[index] = new Entry<>(hash, key, value, e); count++; return null; @@ -470,10 +475,12 @@ public class Hashtable * @throws NullPointerException if the key is null */ public synchronized V remove(Object key) { - Entry tab[] = table; + Entry tab[] = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index], prev = null ; e != null ; prev = e, e = e.next) { + @SuppressWarnings("unchecked") + Entry e = (Entry)tab[index]; + for(Entry prev = null ; e != null ; prev = e, e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { modCount++; if (prev != null) { @@ -508,7 +515,7 @@ public class Hashtable * Clears this hashtable so that it contains no keys. */ public synchronized void clear() { - Entry tab[] = table; + Entry tab[] = table; modCount++; for (int index = tab.length; --index >= 0; ) tab[index] = null; @@ -524,11 +531,11 @@ public class Hashtable */ public synchronized Object clone() { try { - Hashtable t = (Hashtable) super.clone(); - t.table = new Entry[table.length]; + Hashtable t = (Hashtable)super.clone(); + t.table = new Entry[table.length]; for (int i = table.length ; i-- > 0 ; ) { t.table[i] = (table[i] != null) - ? (Entry) table[i].clone() : null; + ? (Entry) table[i].clone() : null; } t.keySet = null; t.entrySet = null; @@ -675,13 +682,13 @@ public class Hashtable public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry)o; + Map.Entry entry = (Map.Entry)o; Object key = entry.getKey(); - Entry[] tab = table; + Entry[] tab = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index]; e != null; e = e.next) + for (Entry e = tab[index]; e != null; e = e.next) if (e.hash==hash && e.equals(entry)) return true; return false; @@ -690,14 +697,15 @@ public class Hashtable public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry) o; - K key = entry.getKey(); - Entry[] tab = table; + Map.Entry entry = (Map.Entry) o; + Object key = entry.getKey(); + Entry[] tab = table; int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index], prev = null; e != null; - prev = e, e = e.next) { + @SuppressWarnings("unchecked") + Entry e = (Entry)tab[index]; + for(Entry prev = null; e != null; prev = e, e = e.next) { if (e.hash==hash && e.equals(entry)) { modCount++; if (prev != null) @@ -776,7 +784,7 @@ public class Hashtable if (!(o instanceof Map)) return false; - Map t = (Map) o; + Map t = (Map) o; if (t.size() != size()) return false; @@ -826,9 +834,9 @@ public class Hashtable return h; // Returns zero loadFactor = -loadFactor; // Mark hashCode computation in progress - Entry[] tab = table; + Entry[] tab = table; for (int i = 0; i < tab.length; i++) - for (Entry e = tab[i]; e != null; e = e.next) + for (Entry e = tab[i]; e != null; e = e.next) h += e.key.hashCode() ^ e.value.hashCode(); loadFactor = -loadFactor; // Mark hashCode computation complete @@ -859,7 +867,7 @@ public class Hashtable // Stack copies of the entries in the table for (int index = 0; index < table.length; index++) { - Entry entry = table[index]; + Entry entry = table[index]; while (entry != null) { entryStack = @@ -899,14 +907,15 @@ public class Hashtable length--; if (origlength > 0 && length > origlength) length = origlength; - - Entry[] table = new Entry[length]; + Entry[] table = new Entry[length]; count = 0; // Read the number of elements and then all the key/value objects for (; elements > 0; elements--) { - K key = (K)s.readObject(); - V value = (V)s.readObject(); + @SuppressWarnings("unchecked") + K key = (K)s.readObject(); + @SuppressWarnings("unchecked") + V value = (V)s.readObject(); // synch could be eliminated for performance reconstitutionPut(table, key, value); } @@ -924,7 +933,7 @@ public class Hashtable * because we are creating a new instance. Also, no return value * is needed. */ - private void reconstitutionPut(Entry[] tab, K key, V value) + private void reconstitutionPut(Entry[] tab, K key, V value) throws StreamCorruptedException { if (value == null) { @@ -934,13 +943,14 @@ public class Hashtable // This should not happen in deserialized version. int hash = key.hashCode(); int index = (hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index] ; e != null ; e = e.next) { + for (Entry e = tab[index] ; e != null ; e = e.next) { if ((e.hash == hash) && e.key.equals(key)) { throw new java.io.StreamCorruptedException(); } } // Creates the new entry. - Entry e = tab[index]; + @SuppressWarnings("unchecked") + Entry e = (Entry)tab[index]; tab[index] = new Entry<>(hash, key, value, e); count++; } @@ -961,6 +971,7 @@ public class Hashtable this.next = next; } + @SuppressWarnings("unchecked") protected Object clone() { return new Entry<>(hash, key, value, (next==null ? null : (Entry) next.clone())); @@ -988,7 +999,7 @@ public class Hashtable public boolean equals(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry)o; return (key==null ? e.getKey()==null : key.equals(e.getKey())) && (value==null ? e.getValue()==null : value.equals(e.getValue())); @@ -1016,10 +1027,10 @@ public class Hashtable * by passing an Enumeration. */ private class Enumerator implements Enumeration, Iterator { - Entry[] table = Hashtable.this.table; + Entry[] table = Hashtable.this.table; int index = table.length; - Entry entry = null; - Entry lastReturned = null; + Entry entry = null; + Entry lastReturned = null; int type; /** @@ -1041,9 +1052,9 @@ public class Hashtable } public boolean hasMoreElements() { - Entry e = entry; + Entry e = entry; int i = index; - Entry[] t = table; + Entry[] t = table; /* Use locals for faster loop iteration */ while (e == null && i > 0) { e = t[--i]; @@ -1053,10 +1064,11 @@ public class Hashtable return e != null; } + @SuppressWarnings("unchecked") public T nextElement() { - Entry et = entry; + Entry et = entry; int i = index; - Entry[] t = table; + Entry[] t = table; /* Use locals for faster loop iteration */ while (et == null && i > 0) { et = t[--i]; @@ -1064,7 +1076,7 @@ public class Hashtable entry = et; index = i; if (et != null) { - Entry e = lastReturned = entry; + Entry e = lastReturned = entry; entry = e.next; return type == KEYS ? (T)e.key : (type == VALUES ? (T)e.value : (T)e); } @@ -1091,11 +1103,12 @@ public class Hashtable throw new ConcurrentModificationException(); synchronized(Hashtable.this) { - Entry[] tab = Hashtable.this.table; + Entry[] tab = Hashtable.this.table; int index = (lastReturned.hash & 0x7FFFFFFF) % tab.length; - for (Entry e = tab[index], prev = null; e != null; - prev = e, e = e.next) { + @SuppressWarnings("unchecked") + Entry e = (Entry)tab[index]; + for(Entry prev = null; e != null; prev = e, e = e.next) { if (e == lastReturned) { modCount++; expectedModCount++; diff --git a/src/share/classes/java/util/IdentityHashMap.java b/src/share/classes/java/util/IdentityHashMap.java index 930c3ac108d46164a50a9434ba2f5bd977e8e0d2..6355557df6d1383b93b0013ccb650285f8841add 100644 --- a/src/share/classes/java/util/IdentityHashMap.java +++ b/src/share/classes/java/util/IdentityHashMap.java @@ -327,6 +327,7 @@ public class IdentityHashMap * * @see #put(Object, Object) */ + @SuppressWarnings("unchecked") public V get(Object key) { Object k = maskNull(key); Object[] tab = table; @@ -431,7 +432,8 @@ public class IdentityHashMap Object item; while ( (item = tab[i]) != null) { if (item == k) { - V oldValue = (V) tab[i + 1]; + @SuppressWarnings("unchecked") + V oldValue = (V) tab[i + 1]; tab[i + 1] = value; return oldValue; } @@ -524,7 +526,8 @@ public class IdentityHashMap if (item == k) { modCount++; size--; - V oldValue = (V) tab[i + 1]; + @SuppressWarnings("unchecked") + V oldValue = (V) tab[i + 1]; tab[i + 1] = null; tab[i] = null; closeDeletion(i); @@ -638,7 +641,7 @@ public class IdentityHashMap if (o == this) { return true; } else if (o instanceof IdentityHashMap) { - IdentityHashMap m = (IdentityHashMap) o; + IdentityHashMap m = (IdentityHashMap) o; if (m.size() != size) return false; @@ -650,7 +653,7 @@ public class IdentityHashMap } return true; } else if (o instanceof Map) { - Map m = (Map)o; + Map m = (Map)o; return entrySet().equals(m.entrySet()); } else { return false; // o is not a Map @@ -698,7 +701,7 @@ public class IdentityHashMap */ public Object clone() { try { - IdentityHashMap m = (IdentityHashMap) super.clone(); + IdentityHashMap m = (IdentityHashMap) super.clone(); m.entrySet = null; m.table = table.clone(); return m; @@ -768,7 +771,7 @@ public class IdentityHashMap int len = tab.length; int d = deletedSlot; - K key = (K) tab[d]; + Object key = tab[d]; tab[d] = null; // vacate the slot tab[d + 1] = null; @@ -818,12 +821,14 @@ public class IdentityHashMap } private class KeyIterator extends IdentityHashMapIterator { + @SuppressWarnings("unchecked") public K next() { return (K) unmaskNull(traversalTable[nextIndex()]); } } private class ValueIterator extends IdentityHashMapIterator { + @SuppressWarnings("unchecked") public V next() { return (V) traversalTable[nextIndex() + 1]; } @@ -854,16 +859,19 @@ public class IdentityHashMap this.index = index; } + @SuppressWarnings("unchecked") public K getKey() { checkIndexForEntryUse(); return (K) unmaskNull(traversalTable[index]); } + @SuppressWarnings("unchecked") public V getValue() { checkIndexForEntryUse(); return (V) traversalTable[index+1]; } + @SuppressWarnings("unchecked") public V setValue(V value) { checkIndexForEntryUse(); V oldValue = (V) traversalTable[index+1]; @@ -880,7 +888,7 @@ public class IdentityHashMap if (!(o instanceof Map.Entry)) return false; - Map.Entry e = (Map.Entry)o; + Map.Entry e = (Map.Entry)o; return (e.getKey() == unmaskNull(traversalTable[index]) && e.getValue() == traversalTable[index+1]); } @@ -1109,13 +1117,13 @@ public class IdentityHashMap public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry)o; + Map.Entry entry = (Map.Entry)o; return containsMapping(entry.getKey(), entry.getValue()); } public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry)o; + Map.Entry entry = (Map.Entry)o; return removeMapping(entry.getKey(), entry.getValue()); } public int size() { @@ -1213,8 +1221,10 @@ public class IdentityHashMap // Read the keys and values, and put the mappings in the table for (int i=0; i private void putForCreate(K key, V value) throws IOException { - K k = (K)maskNull(key); + Object k = maskNull(key); Object[] tab = table; int len = tab.length; int i = hash(k, len); diff --git a/src/share/classes/java/util/IllegalFormatConversionException.java b/src/share/classes/java/util/IllegalFormatConversionException.java index 9bdbfc41dae5c117b8a18fdac89ca0f2d9ec8a51..2b30922c04769552ebaa41922b03bdb916774fe2 100644 --- a/src/share/classes/java/util/IllegalFormatConversionException.java +++ b/src/share/classes/java/util/IllegalFormatConversionException.java @@ -40,7 +40,7 @@ public class IllegalFormatConversionException extends IllegalFormatException { private static final long serialVersionUID = 17000126L; private char c; - private Class arg; + private Class arg; /** * Constructs an instance of this class with the mismatched conversion and diff --git a/src/share/classes/java/util/JumboEnumSet.java b/src/share/classes/java/util/JumboEnumSet.java index 93802107bd4e33b0c31fafdf34cc72993c52164a..5db15bbdace54d1c1ad58cd6f643abfa9a4fdf5f 100644 --- a/src/share/classes/java/util/JumboEnumSet.java +++ b/src/share/classes/java/util/JumboEnumSet.java @@ -46,7 +46,7 @@ class JumboEnumSet> extends EnumSet { // Redundant - maintained for performance private int size = 0; - JumboEnumSet(ClasselementType, Enum[] universe) { + JumboEnumSet(ClasselementType, Enum[] universe) { super(elementType, universe); elements = new long[(universe.length + 63) >>> 6]; } @@ -127,6 +127,7 @@ class JumboEnumSet> extends EnumSet { return unseen != 0; } + @Override public E next() { if (!hasNext()) throw new NoSuchElementException(); @@ -176,11 +177,11 @@ class JumboEnumSet> extends EnumSet { public boolean contains(Object e) { if (e == null) return false; - Class eClass = e.getClass(); + Class eClass = e.getClass(); if (eClass != elementType && eClass.getSuperclass() != elementType) return false; - int eOrdinal = ((Enum)e).ordinal(); + int eOrdinal = ((Enum)e).ordinal(); return (elements[eOrdinal >>> 6] & (1L << eOrdinal)) != 0; } @@ -217,10 +218,10 @@ class JumboEnumSet> extends EnumSet { public boolean remove(Object e) { if (e == null) return false; - Class eClass = e.getClass(); + Class eClass = e.getClass(); if (eClass != elementType && eClass.getSuperclass() != elementType) return false; - int eOrdinal = ((Enum)e).ordinal(); + int eOrdinal = ((Enum)e).ordinal(); int eWordNum = eOrdinal >>> 6; long oldElements = elements[eWordNum]; @@ -246,7 +247,7 @@ class JumboEnumSet> extends EnumSet { if (!(c instanceof JumboEnumSet)) return super.containsAll(c); - JumboEnumSet es = (JumboEnumSet)c; + JumboEnumSet es = (JumboEnumSet)c; if (es.elementType != elementType) return es.isEmpty(); @@ -268,7 +269,7 @@ class JumboEnumSet> extends EnumSet { if (!(c instanceof JumboEnumSet)) return super.addAll(c); - JumboEnumSet es = (JumboEnumSet)c; + JumboEnumSet es = (JumboEnumSet)c; if (es.elementType != elementType) { if (es.isEmpty()) return false; @@ -294,7 +295,7 @@ class JumboEnumSet> extends EnumSet { if (!(c instanceof JumboEnumSet)) return super.removeAll(c); - JumboEnumSet es = (JumboEnumSet)c; + JumboEnumSet es = (JumboEnumSet)c; if (es.elementType != elementType) return false; @@ -348,7 +349,7 @@ class JumboEnumSet> extends EnumSet { if (!(o instanceof JumboEnumSet)) return super.equals(o); - JumboEnumSet es = (JumboEnumSet)o; + JumboEnumSet es = (JumboEnumSet)o; if (es.elementType != elementType) return size == 0 && es.size == 0; diff --git a/src/share/classes/java/util/LinkedHashMap.java b/src/share/classes/java/util/LinkedHashMap.java index 4f80ec4f273ad43469a4f875e1ef9dbb2989eb98..5e656c8d78ec0249f4ece1020aeb70c0c9abb499 100644 --- a/src/share/classes/java/util/LinkedHashMap.java +++ b/src/share/classes/java/util/LinkedHashMap.java @@ -246,11 +246,12 @@ public class LinkedHashMap * by superclass resize. It is overridden for performance, as it is * faster to iterate using our linked list. */ + @SuppressWarnings("unchecked") void transfer(HashMap.Entry[] newTable) { int newCapacity = newTable.length; for (Entry e = header.after; e != header; e = e.after) { int index = indexFor(e.hash, newCapacity); - e.next = newTable[index]; + e.next = (HashMap.Entry)newTable[index]; newTable[index] = e; } } @@ -267,11 +268,11 @@ public class LinkedHashMap public boolean containsValue(Object value) { // Overridden to take advantage of faster iterator if (value==null) { - for (Entry e = header.after; e != header; e = e.after) + for (Entry e = header.after; e != header; e = e.after) if (e.value==null) return true; } else { - for (Entry e = header.after; e != header; e = e.after) + for (Entry e = header.after; e != header; e = e.after) if (value.equals(e.value)) return true; } @@ -437,7 +438,8 @@ public class LinkedHashMap * table or remove the eldest entry. */ void createEntry(int hash, K key, V value, int bucketIndex) { - HashMap.Entry old = table[bucketIndex]; + @SuppressWarnings("unchecked") + HashMap.Entry old = (HashMap.Entry)table[bucketIndex]; Entry e = new Entry<>(hash, key, value, old); table[bucketIndex] = e; e.addBefore(header); diff --git a/src/share/classes/java/util/Observable.java b/src/share/classes/java/util/Observable.java index 7104071ff622639a6dab0293bc818eaa88d51749..25295e8444f2ed58f1fadddc4d05780f69d42663 100644 --- a/src/share/classes/java/util/Observable.java +++ b/src/share/classes/java/util/Observable.java @@ -61,12 +61,12 @@ package java.util; */ public class Observable { private boolean changed = false; - private Vector obs; + private Vector obs; /** Construct an Observable with zero Observers. */ public Observable() { - obs = new Vector(); + obs = new Vector<>(); } /** diff --git a/src/share/classes/java/util/PriorityQueue.java b/src/share/classes/java/util/PriorityQueue.java index b4416ab2d4b63a888c5eb0c806ad8ed5c2a48b7e..bb9c114dd681f070e47a2a7fefbedab669f48c8d 100644 --- a/src/share/classes/java/util/PriorityQueue.java +++ b/src/share/classes/java/util/PriorityQueue.java @@ -449,6 +449,7 @@ public class PriorityQueue extends AbstractQueue * this queue * @throws NullPointerException if the specified array is null */ + @SuppressWarnings("unchecked") public T[] toArray(T[] a) { if (a.length < size) // Make a new array of a's runtime type, but my contents: @@ -514,6 +515,7 @@ public class PriorityQueue extends AbstractQueue (forgetMeNot != null && !forgetMeNot.isEmpty()); } + @SuppressWarnings("unchecked") public E next() { if (expectedModCount != modCount) throw new ConcurrentModificationException(); @@ -571,8 +573,10 @@ public class PriorityQueue extends AbstractQueue return null; int s = --size; modCount++; - E result = (E) queue[0]; - E x = (E) queue[s]; + @SuppressWarnings("unchecked") + E result = (E) queue[0]; + @SuppressWarnings("unchecked") + E x = (E) queue[s]; queue[s] = null; if (s != 0) siftDown(0, x); @@ -598,7 +602,8 @@ public class PriorityQueue extends AbstractQueue if (s == i) // removed last element queue[i] = null; else { - E moved = (E) queue[s]; + @SuppressWarnings("unchecked") + E moved = (E) queue[s]; queue[s] = null; siftDown(i, moved); if (queue[i] == moved) { @@ -629,6 +634,7 @@ public class PriorityQueue extends AbstractQueue siftUpComparable(k, x); } + @SuppressWarnings("unchecked") private void siftUpComparable(int k, E x) { Comparable key = (Comparable) x; while (k > 0) { @@ -645,8 +651,9 @@ public class PriorityQueue extends AbstractQueue private void siftUpUsingComparator(int k, E x) { while (k > 0) { int parent = (k - 1) >>> 1; - Object e = queue[parent]; - if (comparator.compare(x, (E) e) >= 0) + @SuppressWarnings("unchecked") + E e = (E) queue[parent]; + if (comparator.compare(x, e) >= 0) break; queue[k] = e; k = parent; @@ -669,6 +676,7 @@ public class PriorityQueue extends AbstractQueue siftDownComparable(k, x); } + @SuppressWarnings("unchecked") private void siftDownComparable(int k, E x) { Comparable key = (Comparable)x; int half = size >>> 1; // loop while a non-leaf @@ -687,6 +695,7 @@ public class PriorityQueue extends AbstractQueue queue[k] = key; } + @SuppressWarnings("unchecked") private void siftDownUsingComparator(int k, E x) { int half = size >>> 1; while (k < half) { @@ -708,6 +717,7 @@ public class PriorityQueue extends AbstractQueue * Establishes the heap invariant (described above) in the entire tree, * assuming nothing about the order of the elements prior to the call. */ + @SuppressWarnings("unchecked") private void heapify() { for (int i = (size >>> 1) - 1; i >= 0; i--) siftDown(i, (E) queue[i]); diff --git a/src/share/classes/java/util/Properties.java b/src/share/classes/java/util/Properties.java index 7c7e13b6a9dc0a6539aef1a2570b09b35d11fa7b..c2fdad48cda21a17347b732585e403dfd9874f8a 100644 --- a/src/share/classes/java/util/Properties.java +++ b/src/share/classes/java/util/Properties.java @@ -824,7 +824,7 @@ class Properties extends Hashtable { bw.write("#" + new Date().toString()); bw.newLine(); synchronized (this) { - for (Enumeration e = keys(); e.hasMoreElements();) { + for (Enumeration e = keys(); e.hasMoreElements();) { String key = (String)e.nextElement(); String val = (String)get(key); key = saveConvert(key, true, escUnicode); @@ -987,7 +987,7 @@ class Properties extends Hashtable { * @see #stringPropertyNames */ public Enumeration propertyNames() { - Hashtable h = new Hashtable(); + Hashtable h = new Hashtable<>(); enumerate(h); return h.keys(); } @@ -1026,10 +1026,10 @@ class Properties extends Hashtable { */ public void list(PrintStream out) { out.println("-- listing properties --"); - Hashtable h = new Hashtable(); + Hashtable h = new Hashtable<>(); enumerate(h); - for (Enumeration e = h.keys() ; e.hasMoreElements() ;) { - String key = (String)e.nextElement(); + for (Enumeration e = h.keys() ; e.hasMoreElements() ;) { + String key = e.nextElement(); String val = (String)h.get(key); if (val.length() > 40) { val = val.substring(0, 37) + "..."; @@ -1054,10 +1054,10 @@ class Properties extends Hashtable { */ public void list(PrintWriter out) { out.println("-- listing properties --"); - Hashtable h = new Hashtable(); + Hashtable h = new Hashtable<>(); enumerate(h); - for (Enumeration e = h.keys() ; e.hasMoreElements() ;) { - String key = (String)e.nextElement(); + for (Enumeration e = h.keys() ; e.hasMoreElements() ;) { + String key = e.nextElement(); String val = (String)h.get(key); if (val.length() > 40) { val = val.substring(0, 37) + "..."; @@ -1072,11 +1072,11 @@ class Properties extends Hashtable { * @throws ClassCastException if any of the property keys * is not of String type. */ - private synchronized void enumerate(Hashtable h) { + private synchronized void enumerate(Hashtable h) { if (defaults != null) { defaults.enumerate(h); } - for (Enumeration e = keys() ; e.hasMoreElements() ;) { + for (Enumeration e = keys() ; e.hasMoreElements() ;) { String key = (String)e.nextElement(); h.put(key, get(key)); } @@ -1091,7 +1091,7 @@ class Properties extends Hashtable { if (defaults != null) { defaults.enumerateStringProperties(h); } - for (Enumeration e = keys() ; e.hasMoreElements() ;) { + for (Enumeration e = keys() ; e.hasMoreElements() ;) { Object k = e.nextElement(); Object v = get(k); if (k instanceof String && v instanceof String) { diff --git a/src/share/classes/java/util/PropertyPermission.java b/src/share/classes/java/util/PropertyPermission.java index 177318835980b0772a21ccef3c5a8eadd36f5562..c89b28bf4d2425edd6a45e97f90ac3cabed54846 100644 --- a/src/share/classes/java/util/PropertyPermission.java +++ b/src/share/classes/java/util/PropertyPermission.java @@ -442,7 +442,7 @@ implements Serializable * Key is property name; value is PropertyPermission. * Not serialized; see serialization section at end of class. */ - private transient Map perms; + private transient Map perms; /** * Boolean saying if "*" is in the collection. @@ -488,7 +488,7 @@ implements Serializable String propName = pp.getName(); synchronized (this) { - PropertyPermission existing = (PropertyPermission) perms.get(propName); + PropertyPermission existing = perms.get(propName); if (existing != null) { int oldMask = existing.getMask(); @@ -499,7 +499,7 @@ implements Serializable perms.put(propName, new PropertyPermission(propName, actions)); } } else { - perms.put(propName, permission); + perms.put(propName, pp); } } @@ -533,7 +533,7 @@ implements Serializable // short circuit if the "*" Permission was added if (all_allowed) { synchronized (this) { - x = (PropertyPermission) perms.get("*"); + x = perms.get("*"); } if (x != null) { effective |= x.getMask(); @@ -550,7 +550,7 @@ implements Serializable //System.out.println("check "+name); synchronized (this) { - x = (PropertyPermission) perms.get(name); + x = perms.get(name); } if (x != null) { @@ -570,7 +570,7 @@ implements Serializable name = name.substring(0, last+1) + "*"; //System.out.println("check "+name); synchronized (this) { - x = (PropertyPermission) perms.get(name); + x = perms.get(name); } if (x != null) { @@ -592,11 +592,15 @@ implements Serializable * * @return an enumeration of all the PropertyPermission objects. */ - + @SuppressWarnings("unchecked") public Enumeration elements() { // Convert Iterator of Map values into an Enumeration synchronized (this) { - return Collections.enumeration(perms.values()); + /** + * Casting to rawtype since Enumeration + * cannot be directly cast to Enumeration + */ + return (Enumeration)Collections.enumeration(perms.values()); } } @@ -633,7 +637,8 @@ implements Serializable // Don't call out.defaultWriteObject() // Copy perms into a Hashtable - Hashtable permissions = new Hashtable<>(perms.size()*2); + Hashtable permissions = + new Hashtable<>(perms.size()*2); synchronized (this) { permissions.putAll(perms); } @@ -661,8 +666,8 @@ implements Serializable // Get permissions @SuppressWarnings("unchecked") - Hashtable permissions = - (Hashtable)gfields.get("permissions", null); + Hashtable permissions = + (Hashtable)gfields.get("permissions", null); perms = new HashMap<>(permissions.size()*2); perms.putAll(permissions); } diff --git a/src/share/classes/java/util/RegularEnumSet.java b/src/share/classes/java/util/RegularEnumSet.java index 4bcb5780b00cdfb7f6e203a5e2a276d2de405fb8..63f5f52e664c1eba14964209b99b4ef011fe4c2a 100644 --- a/src/share/classes/java/util/RegularEnumSet.java +++ b/src/share/classes/java/util/RegularEnumSet.java @@ -41,7 +41,7 @@ class RegularEnumSet> extends EnumSet { */ private long elements = 0L; - RegularEnumSet(ClasselementType, Enum[] universe) { + RegularEnumSet(ClasselementType, Enum[] universe) { super(elementType, universe); } @@ -96,6 +96,7 @@ class RegularEnumSet> extends EnumSet { return unseen != 0; } + @SuppressWarnings("unchecked") public E next() { if (unseen == 0) throw new NoSuchElementException(); @@ -139,11 +140,11 @@ class RegularEnumSet> extends EnumSet { public boolean contains(Object e) { if (e == null) return false; - Class eClass = e.getClass(); + Class eClass = e.getClass(); if (eClass != elementType && eClass.getSuperclass() != elementType) return false; - return (elements & (1L << ((Enum)e).ordinal())) != 0; + return (elements & (1L << ((Enum)e).ordinal())) != 0; } // Modification Operations @@ -160,7 +161,7 @@ class RegularEnumSet> extends EnumSet { typeCheck(e); long oldElements = elements; - elements |= (1L << ((Enum)e).ordinal()); + elements |= (1L << ((Enum)e).ordinal()); return elements != oldElements; } @@ -173,12 +174,12 @@ class RegularEnumSet> extends EnumSet { public boolean remove(Object e) { if (e == null) return false; - Class eClass = e.getClass(); + Class eClass = e.getClass(); if (eClass != elementType && eClass.getSuperclass() != elementType) return false; long oldElements = elements; - elements &= ~(1L << ((Enum)e).ordinal()); + elements &= ~(1L << ((Enum)e).ordinal()); return elements != oldElements; } @@ -197,7 +198,7 @@ class RegularEnumSet> extends EnumSet { if (!(c instanceof RegularEnumSet)) return super.containsAll(c); - RegularEnumSet es = (RegularEnumSet)c; + RegularEnumSet es = (RegularEnumSet)c; if (es.elementType != elementType) return es.isEmpty(); @@ -216,7 +217,7 @@ class RegularEnumSet> extends EnumSet { if (!(c instanceof RegularEnumSet)) return super.addAll(c); - RegularEnumSet es = (RegularEnumSet)c; + RegularEnumSet es = (RegularEnumSet)c; if (es.elementType != elementType) { if (es.isEmpty()) return false; @@ -242,7 +243,7 @@ class RegularEnumSet> extends EnumSet { if (!(c instanceof RegularEnumSet)) return super.removeAll(c); - RegularEnumSet es = (RegularEnumSet)c; + RegularEnumSet es = (RegularEnumSet)c; if (es.elementType != elementType) return false; @@ -295,7 +296,7 @@ class RegularEnumSet> extends EnumSet { if (!(o instanceof RegularEnumSet)) return super.equals(o); - RegularEnumSet es = (RegularEnumSet)o; + RegularEnumSet es = (RegularEnumSet)o; if (es.elementType != elementType) return elements == 0 && es.elements == 0; return es.elements == elements; diff --git a/src/share/classes/java/util/ResourceBundle.java b/src/share/classes/java/util/ResourceBundle.java index c7b425db7ac581311b370b62b6e6e45c1e71c80e..6be14d590fad9e004f53a56dbf168c72822c2120 100644 --- a/src/share/classes/java/util/ResourceBundle.java +++ b/src/share/classes/java/util/ResourceBundle.java @@ -294,7 +294,8 @@ public abstract class ResourceBundle { /** * Queue for reference objects referring to class loaders or bundles. */ - private static final ReferenceQueue referenceQueue = new ReferenceQueue<>(); + private static final ReferenceQueue referenceQueue = + new ReferenceQueue<>(); /** * The parent bundle of this bundle. @@ -417,7 +418,7 @@ public abstract class ResourceBundle { * caller's caller. */ private static ClassLoader getLoader() { - Class[] stack = getClassContext(); + Class[] stack = getClassContext(); /* Magic number 2 identifies our caller's caller */ Class c = stack[2]; ClassLoader cl = (c == null) ? null : c.getClassLoader(); @@ -434,7 +435,7 @@ public abstract class ResourceBundle { return cl; } - private static native Class[] getClassContext(); + private static native Class[] getClassContext(); /** * A wrapper of ClassLoader.getSystemClassLoader(). diff --git a/src/share/classes/java/util/ServiceLoader.java b/src/share/classes/java/util/ServiceLoader.java index b3c34ae24cfa48c21d694c522be101c58fc45104..62aa9dd2453c0f4232334b089a3d65537615c665 100644 --- a/src/share/classes/java/util/ServiceLoader.java +++ b/src/share/classes/java/util/ServiceLoader.java @@ -218,20 +218,20 @@ public final class ServiceLoader reload(); } - private static void fail(Class service, String msg, Throwable cause) + private static void fail(Class service, String msg, Throwable cause) throws ServiceConfigurationError { throw new ServiceConfigurationError(service.getName() + ": " + msg, cause); } - private static void fail(Class service, String msg) + private static void fail(Class service, String msg) throws ServiceConfigurationError { 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 { fail(service, u + ":" + line + ": " + msg); @@ -240,7 +240,7 @@ public final class ServiceLoader // Parse a single line from the given configuration file, adding the name // on the line to the names list. // - private int parseLine(Class service, URL u, BufferedReader r, int lc, + private int parseLine(Class service, URL u, BufferedReader r, int lc, List names) throws IOException, ServiceConfigurationError { @@ -286,7 +286,7 @@ public final class ServiceLoader // If an I/O error occurs while reading from the given URL, or // if a configuration-file format error is detected // - private Iterator parse(Class service, URL u) + private Iterator parse(Class service, URL u) throws ServiceConfigurationError { InputStream in = null; diff --git a/src/share/classes/java/util/TimeZone.java b/src/share/classes/java/util/TimeZone.java index e9d6cef056bbf27d7f26e53ed2bab5b75cfba79c..647e350e4b39d2788293a412e1a731d79bce0e01 100644 --- a/src/share/classes/java/util/TimeZone.java +++ b/src/share/classes/java/util/TimeZone.java @@ -428,7 +428,7 @@ abstract public class TimeZone implements Serializable, Cloneable { // The structure is: // Map(key=id, value=SoftReference(Map(key=locale, value=displaynames))) private static final Map>> CACHE = - new ConcurrentHashMap>>(); + new ConcurrentHashMap<>(); } private static final String[] getDisplayNames(String id, Locale locale) { @@ -452,9 +452,9 @@ abstract public class TimeZone implements Serializable, Cloneable { String[] names = TimeZoneNameUtility.retrieveDisplayNames(id, locale); if (names != null) { - Map perLocale = new ConcurrentHashMap(); + Map perLocale = new ConcurrentHashMap<>(); perLocale.put(locale, names); - ref = new SoftReference>(perLocale); + ref = new SoftReference<>(perLocale); displayNames.put(id, ref); } return names; diff --git a/src/share/classes/java/util/TreeMap.java b/src/share/classes/java/util/TreeMap.java index c7aae652466e36aee21bdea9e1b09f8c6d5c128a..dfa1509774e4876a88c7961cbb08ddee74932bdc 100644 --- a/src/share/classes/java/util/TreeMap.java +++ b/src/share/classes/java/util/TreeMap.java @@ -307,7 +307,7 @@ public class TreeMap public void putAll(Map map) { int mapSize = map.size(); if (size==0 && mapSize!=0 && map instanceof SortedMap) { - Comparator c = ((SortedMap)map).comparator(); + Comparator c = ((SortedMap)map).comparator(); if (c == comparator || (c != null && c.equals(comparator))) { ++modCount; try { @@ -340,7 +340,8 @@ public class TreeMap return getEntryUsingComparator(key); if (key == null) throw new NullPointerException(); - Comparable k = (Comparable) key; + @SuppressWarnings("unchecked") + Comparable k = (Comparable) key; Entry p = root; while (p != null) { int cmp = k.compareTo(p.key); @@ -361,7 +362,8 @@ public class TreeMap * worthwhile here.) */ final Entry getEntryUsingComparator(Object key) { - K k = (K) key; + @SuppressWarnings("unchecked") + K k = (K) key; Comparator cpr = comparator; if (cpr != null) { Entry p = root; @@ -554,7 +556,8 @@ public class TreeMap else { if (key == null) throw new NullPointerException(); - Comparable k = (Comparable) key; + @SuppressWarnings("unchecked") + Comparable k = (Comparable) key; do { parent = t; cmp = k.compareTo(t.key); @@ -618,9 +621,9 @@ public class TreeMap * @return a shallow copy of this map */ public Object clone() { - TreeMap clone = null; + TreeMap clone; try { - clone = (TreeMap) super.clone(); + clone = (TreeMap) super.clone(); } catch (CloneNotSupportedException e) { throw new InternalError(e); } @@ -803,7 +806,7 @@ public class TreeMap */ public NavigableSet navigableKeySet() { KeySet nks = navigableKeySet; - return (nks != null) ? nks : (navigableKeySet = new KeySet(this)); + return (nks != null) ? nks : (navigableKeySet = new KeySet<>(this)); } /** @@ -859,9 +862,9 @@ public class TreeMap public NavigableMap descendingMap() { NavigableMap km = descendingMap; return (km != null) ? km : - (descendingMap = new DescendingSubMap(this, - true, null, true, - true, null, true)); + (descendingMap = new DescendingSubMap<>(this, + true, null, true, + true, null, true)); } /** @@ -874,9 +877,9 @@ public class TreeMap */ public NavigableMap subMap(K fromKey, boolean fromInclusive, K toKey, boolean toInclusive) { - return new AscendingSubMap(this, - false, fromKey, fromInclusive, - false, toKey, toInclusive); + return new AscendingSubMap<>(this, + false, fromKey, fromInclusive, + false, toKey, toInclusive); } /** @@ -888,9 +891,9 @@ public class TreeMap * @since 1.6 */ public NavigableMap headMap(K toKey, boolean inclusive) { - return new AscendingSubMap(this, - true, null, true, - false, toKey, inclusive); + return new AscendingSubMap<>(this, + true, null, true, + false, toKey, inclusive); } /** @@ -902,9 +905,9 @@ public class TreeMap * @since 1.6 */ public NavigableMap tailMap(K fromKey, boolean inclusive) { - return new AscendingSubMap(this, - false, fromKey, inclusive, - true, null, true); + return new AscendingSubMap<>(this, + false, fromKey, inclusive, + true, null, true); } /** @@ -978,8 +981,8 @@ public class TreeMap public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry) o; - V value = entry.getValue(); + Map.Entry entry = (Map.Entry) o; + Object value = entry.getValue(); Entry p = getEntry(entry.getKey()); return p != null && valEquals(p.getValue(), value); } @@ -987,8 +990,8 @@ public class TreeMap public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry) o; - V value = entry.getValue(); + Map.Entry entry = (Map.Entry) o; + Object value = entry.getValue(); Entry p = getEntry(entry.getKey()); if (p != null && valEquals(p.getValue(), value)) { deleteEntry(p); @@ -1023,21 +1026,21 @@ public class TreeMap } static final class KeySet extends AbstractSet implements NavigableSet { - private final NavigableMap m; - KeySet(NavigableMap map) { m = map; } + private final NavigableMap m; + KeySet(NavigableMap map) { m = map; } public Iterator iterator() { if (m instanceof TreeMap) - return ((TreeMap)m).keyIterator(); + return ((TreeMap)m).keyIterator(); else - return (Iterator)(((TreeMap.NavigableSubMap)m).keyIterator()); + return ((TreeMap.NavigableSubMap)m).keyIterator(); } public Iterator descendingIterator() { if (m instanceof TreeMap) - return ((TreeMap)m).descendingKeyIterator(); + return ((TreeMap)m).descendingKeyIterator(); else - return (Iterator)(((TreeMap.NavigableSubMap)m).descendingKeyIterator()); + return ((TreeMap.NavigableSubMap)m).descendingKeyIterator(); } public int size() { return m.size(); } @@ -1052,11 +1055,11 @@ public class TreeMap public E last() { return m.lastKey(); } public Comparator comparator() { return m.comparator(); } public E pollFirst() { - Map.Entry e = m.pollFirstEntry(); + Map.Entry e = m.pollFirstEntry(); return (e == null) ? null : e.getKey(); } public E pollLast() { - Map.Entry e = m.pollLastEntry(); + Map.Entry e = m.pollLastEntry(); return (e == null) ? null : e.getKey(); } public boolean remove(Object o) { @@ -1085,7 +1088,7 @@ public class TreeMap return tailSet(fromElement, true); } public NavigableSet descendingSet() { - return new KeySet(m.descendingMap()); + return new KeySet<>(m.descendingMap()); } } @@ -1184,6 +1187,7 @@ public class TreeMap /** * Compares two keys using the correct comparison method for this TreeMap. */ + @SuppressWarnings("unchecked") final int compare(Object k1, Object k2) { return comparator==null ? ((Comparable)k1).compareTo((K)k2) : comparator.compare((K)k1, (K)k2); @@ -1488,7 +1492,7 @@ public class TreeMap public final NavigableSet navigableKeySet() { KeySet nksv = navigableKeySetView; return (nksv != null) ? nksv : - (navigableKeySetView = new TreeMap.KeySet(this)); + (navigableKeySetView = new TreeMap.KeySet<>(this)); } public final Set keySet() { @@ -1522,7 +1526,7 @@ public class TreeMap if (size == -1 || sizeModCount != m.modCount) { sizeModCount = m.modCount; size = 0; - Iterator i = iterator(); + Iterator i = iterator(); while (i.hasNext()) { size++; i.next(); @@ -1539,11 +1543,11 @@ public class TreeMap public boolean contains(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry) o; - K key = entry.getKey(); + Map.Entry entry = (Map.Entry) o; + Object key = entry.getKey(); if (!inRange(key)) return false; - TreeMap.Entry node = m.getEntry(key); + TreeMap.Entry node = m.getEntry(key); return node != null && valEquals(node.getValue(), entry.getValue()); } @@ -1551,8 +1555,8 @@ public class TreeMap public boolean remove(Object o) { if (!(o instanceof Map.Entry)) return false; - Map.Entry entry = (Map.Entry) o; - K key = entry.getKey(); + Map.Entry entry = (Map.Entry) o; + Object key = entry.getKey(); if (!inRange(key)) return false; TreeMap.Entry node = m.getEntry(key); @@ -1709,34 +1713,34 @@ public class TreeMap throw new IllegalArgumentException("fromKey out of range"); if (!inRange(toKey, toInclusive)) throw new IllegalArgumentException("toKey out of range"); - return new AscendingSubMap(m, - false, fromKey, fromInclusive, - false, toKey, toInclusive); + return new AscendingSubMap<>(m, + false, fromKey, fromInclusive, + false, toKey, toInclusive); } public NavigableMap headMap(K toKey, boolean inclusive) { if (!inRange(toKey, inclusive)) throw new IllegalArgumentException("toKey out of range"); - return new AscendingSubMap(m, - fromStart, lo, loInclusive, - false, toKey, inclusive); + return new AscendingSubMap<>(m, + fromStart, lo, loInclusive, + false, toKey, inclusive); } public NavigableMap tailMap(K fromKey, boolean inclusive) { if (!inRange(fromKey, inclusive)) throw new IllegalArgumentException("fromKey out of range"); - return new AscendingSubMap(m, - false, fromKey, inclusive, - toEnd, hi, hiInclusive); + return new AscendingSubMap<>(m, + false, fromKey, inclusive, + toEnd, hi, hiInclusive); } public NavigableMap descendingMap() { NavigableMap mv = descendingMapView; return (mv != null) ? mv : (descendingMapView = - new DescendingSubMap(m, - fromStart, lo, loInclusive, - toEnd, hi, hiInclusive)); + new DescendingSubMap<>(m, + fromStart, lo, loInclusive, + toEnd, hi, hiInclusive)); } Iterator keyIterator() { @@ -1790,34 +1794,34 @@ public class TreeMap throw new IllegalArgumentException("fromKey out of range"); if (!inRange(toKey, toInclusive)) throw new IllegalArgumentException("toKey out of range"); - return new DescendingSubMap(m, - false, toKey, toInclusive, - false, fromKey, fromInclusive); + return new DescendingSubMap<>(m, + false, toKey, toInclusive, + false, fromKey, fromInclusive); } public NavigableMap headMap(K toKey, boolean inclusive) { if (!inRange(toKey, inclusive)) throw new IllegalArgumentException("toKey out of range"); - return new DescendingSubMap(m, - false, toKey, inclusive, - toEnd, hi, hiInclusive); + return new DescendingSubMap<>(m, + false, toKey, inclusive, + toEnd, hi, hiInclusive); } public NavigableMap tailMap(K fromKey, boolean inclusive) { if (!inRange(fromKey, inclusive)) throw new IllegalArgumentException("fromKey out of range"); - return new DescendingSubMap(m, - fromStart, lo, loInclusive, - false, fromKey, inclusive); + return new DescendingSubMap<>(m, + fromStart, lo, loInclusive, + false, fromKey, inclusive); } public NavigableMap descendingMap() { NavigableMap mv = descendingMapView; return (mv != null) ? mv : (descendingMapView = - new AscendingSubMap(m, - fromStart, lo, loInclusive, - toEnd, hi, hiInclusive)); + new AscendingSubMap<>(m, + fromStart, lo, loInclusive, + toEnd, hi, hiInclusive)); } Iterator keyIterator() { @@ -1862,9 +1866,9 @@ public class TreeMap private boolean fromStart = false, toEnd = false; private K fromKey, toKey; private Object readResolve() { - return new AscendingSubMap(TreeMap.this, - fromStart, fromKey, true, - toEnd, toKey, false); + return new AscendingSubMap<>(TreeMap.this, + fromStart, fromKey, true, + toEnd, toKey, false); } public Set> entrySet() { throw new InternalError(); } public K lastKey() { throw new InternalError(); } @@ -2331,12 +2335,12 @@ public class TreeMap * @param defaultVal if non-null, this default value is used for * each value in the map. If null, each value is read from * iterator or stream, as described above. - * @throws IOException propagated from stream reads. This cannot + * @throws java.io.IOException propagated from stream reads. This cannot * occur if str is null. * @throws ClassNotFoundException propagated from readObject. * This cannot occur if str is null. */ - private void buildFromSorted(int size, Iterator it, + private void buildFromSorted(int size, Iterator it, java.io.ObjectInputStream str, V defaultVal) throws java.io.IOException, ClassNotFoundException { @@ -2359,9 +2363,10 @@ public class TreeMap * @param redLevel the level at which nodes should be red. * Must be equal to computeRedLevel for tree of this size. */ + @SuppressWarnings("unchecked") private final Entry buildFromSorted(int level, int lo, int hi, int redLevel, - Iterator it, + Iterator it, java.io.ObjectInputStream str, V defaultVal) throws java.io.IOException, ClassNotFoundException { @@ -2391,9 +2396,9 @@ public class TreeMap V value; if (it != null) { if (defaultVal==null) { - Map.Entry entry = (Map.Entry)it.next(); - key = entry.getKey(); - value = entry.getValue(); + Map.Entry entry = (Map.Entry)it.next(); + key = (K)entry.getKey(); + value = (V)entry.getValue(); } else { key = (K)it.next(); value = defaultVal; diff --git a/src/share/classes/java/util/TreeSet.java b/src/share/classes/java/util/TreeSet.java index 6b2a33d3b5355d3f2878ee1114a531ecd79aa405..db71096da04bed6ba4918932f9799fff81ddd9d3 100644 --- a/src/share/classes/java/util/TreeSet.java +++ b/src/share/classes/java/util/TreeSet.java @@ -302,7 +302,7 @@ public class TreeSet extends AbstractSet m instanceof TreeMap) { SortedSet set = (SortedSet) c; TreeMap map = (TreeMap) m; - Comparator cc = (Comparator) set.comparator(); + Comparator cc = set.comparator(); Comparator mc = map.comparator(); if (cc==mc || (cc != null && cc.equals(mc))) { map.addAllForTreeSet(set, PRESENT); @@ -469,8 +469,9 @@ public class TreeSet extends AbstractSet * * @return a shallow copy of this set */ + @SuppressWarnings("unchecked") public Object clone() { - TreeSet clone = null; + TreeSet clone; try { clone = (TreeSet) super.clone(); } catch (CloneNotSupportedException e) { @@ -519,14 +520,11 @@ public class TreeSet extends AbstractSet s.defaultReadObject(); // Read in Comparator - Comparator c = (Comparator) s.readObject(); + @SuppressWarnings("unchecked") + Comparator c = (Comparator) s.readObject(); // Create backing TreeMap - TreeMap tm; - if (c==null) - tm = new TreeMap<>(); - else - tm = new TreeMap<>(c); + TreeMap tm = new TreeMap<>(c); m = tm; // Read in size diff --git a/src/share/classes/java/util/WeakHashMap.java b/src/share/classes/java/util/WeakHashMap.java index eb6152069c9fce8ec71c44184b42df7045bc0297..f5f62375e9449aa6c370ca2ffdd4c848501551bb 100644 --- a/src/share/classes/java/util/WeakHashMap.java +++ b/src/share/classes/java/util/WeakHashMap.java @@ -186,7 +186,7 @@ public class WeakHashMap @SuppressWarnings("unchecked") private Entry[] newTable(int n) { - return (Entry[]) new Entry[n]; + return (Entry[]) new Entry[n]; } /** diff --git a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java index 466a5dba0589d6bc075242c5a5c6517afbe4c542..638689350594e877d6f5316a3d5e7dcce9d7d9cc 100644 --- a/src/share/classes/sun/nio/ch/DatagramChannelImpl.java +++ b/src/share/classes/sun/nio/ch/DatagramChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2001, 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 @@ -970,7 +970,8 @@ class DatagramChannelImpl protected void implCloseSelectableChannel() throws IOException { synchronized (stateLock) { - nd.preClose(fd); + if (state != ST_KILLED) + nd.preClose(fd); ResourceManager.afterUdpClose(); // if member of mulitcast group then invalidate all keys diff --git a/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java b/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java index 671fad277337ad2d7c8c7c0bad0f5400667c6af7..a7f90a9660c95c3f4908a300d8e55e6137873005 100644 --- a/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java +++ b/src/share/classes/sun/nio/ch/ServerSocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -261,7 +261,8 @@ class ServerSocketChannelImpl protected void implCloseSelectableChannel() throws IOException { synchronized (stateLock) { - nd.preClose(fd); + if (state != ST_KILLED) + nd.preClose(fd); long th = thread; if (th != 0) NativeThread.signal(th); diff --git a/src/share/classes/sun/nio/ch/SocketChannelImpl.java b/src/share/classes/sun/nio/ch/SocketChannelImpl.java index ba55ab1b0ed0a39ea454ebfe8159fbf77c065e5d..fe2c5fe33ac02a815c21aa0b3ab9194adc5eefd0 100644 --- a/src/share/classes/sun/nio/ch/SocketChannelImpl.java +++ b/src/share/classes/sun/nio/ch/SocketChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -816,7 +816,8 @@ class SocketChannelImpl // channel from using the old fd, which might be recycled in the // meantime and allocated to an entirely different channel. // - nd.preClose(fd); + if (state != ST_KILLED) + nd.preClose(fd); // Signal native threads, if needed. If a target thread is not // currently blocked in an I/O operation then no harm is done since diff --git a/src/share/lib/security/java.security b/src/share/lib/security/java.security index a89d40e194b4097cdb092a55d598cb194644db24..fc48b9e2520da0702a45093331e3da43042bb089 100644 --- a/src/share/lib/security/java.security +++ b/src/share/lib/security/java.security @@ -123,7 +123,7 @@ keystore.type=jks # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. +package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils. # # List of comma-separated packages that start with or equal this string diff --git a/src/share/lib/security/java.security-macosx b/src/share/lib/security/java.security-macosx index 42f9d3a8a634ae310df95cd4ebea1a53f543b1c6..65be54c6db41d6e55010415f41443ca86bad9514 100644 --- a/src/share/lib/security/java.security-macosx +++ b/src/share/lib/security/java.security-macosx @@ -124,7 +124,7 @@ keystore.type=jks # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,apple. +package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,apple.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils. # # List of comma-separated packages that start with or equal this string diff --git a/src/share/lib/security/java.security-solaris b/src/share/lib/security/java.security-solaris index d01cfdafa1cd98617f56ed762fa678b70142e641..1abd2f4f1cdcc12cd8b9b53da444bdf982cf6d1c 100644 --- a/src/share/lib/security/java.security-solaris +++ b/src/share/lib/security/java.security-solaris @@ -125,7 +125,7 @@ keystore.type=jks # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. +package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils. # # List of comma-separated packages that start with or equal this string diff --git a/src/share/lib/security/java.security-windows b/src/share/lib/security/java.security-windows index 3db627a4f325f35703db59b696ceb27ade910fc3..8091e4a2464a8b5614cc23b476a7b35f90689172 100644 --- a/src/share/lib/security/java.security-windows +++ b/src/share/lib/security/java.security-windows @@ -124,7 +124,7 @@ keystore.type=jks # passed to checkPackageAccess unless the # corresponding RuntimePermission ("accessClassInPackage."+package) has # been granted. -package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio. +package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils. # # List of comma-separated packages that start with or equal this string diff --git a/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java b/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java index 6e89d063f2e160857f585f30365b85e113cbe389..e99c184f8e9999af3f02936384d5c9adae406b25 100644 --- a/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java +++ b/src/solaris/classes/sun/nio/ch/SinkChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -84,7 +84,8 @@ class SinkChannelImpl protected void implCloseSelectableChannel() throws IOException { synchronized (stateLock) { - nd.preClose(fd); + if (state != ST_KILLED) + nd.preClose(fd); long th = thread; if (th != 0) NativeThread.signal(th); diff --git a/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java b/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java index 915573b9869314e4b525d1a0db6c4084fa7bbca0..b6b005ae315abb4b89c8b4bd62408c4f0ce5a59a 100644 --- a/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java +++ b/src/solaris/classes/sun/nio/ch/SourceChannelImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -84,7 +84,8 @@ class SourceChannelImpl protected void implCloseSelectableChannel() throws IOException { synchronized (stateLock) { - nd.preClose(fd); + if (state != ST_KILLED) + nd.preClose(fd); long th = thread; if (th != 0) NativeThread.signal(th); diff --git a/src/solaris/native/com/sun/management/MacosxOperatingSystem.c b/src/solaris/native/com/sun/management/MacosxOperatingSystem.c index e2c561bf451ea29d989965fdca2143f40206bdcb..3e7ac65fac46816923d2dda3f792439147511c36 100644 --- a/src/solaris/native/com/sun/management/MacosxOperatingSystem.c +++ b/src/solaris/native/com/sun/management/MacosxOperatingSystem.c @@ -25,16 +25,136 @@ #include "com_sun_management_UnixOperatingSystem.h" +#include +#include +#include + + JNIEXPORT jdouble JNICALL Java_com_sun_management_UnixOperatingSystem_getSystemCpuLoad (JNIEnv *env, jobject dummy) { - return -1.0; // not available + // This code is influenced by the darwin top source + + kern_return_t kr; + mach_msg_type_number_t count; + host_cpu_load_info_data_t load; + + static jlong last_used = 0; + static jlong last_total = 0; + + count = HOST_CPU_LOAD_INFO_COUNT; + kr = host_statistics(mach_host_self(), HOST_CPU_LOAD_INFO, (host_info_t)&load, &count); + if (kr != KERN_SUCCESS) { + return -1; + } + + jlong used = load.cpu_ticks[CPU_STATE_USER] + load.cpu_ticks[CPU_STATE_NICE] + load.cpu_ticks[CPU_STATE_SYSTEM]; + jlong total = used + load.cpu_ticks[CPU_STATE_IDLE]; + + if (last_used == 0 || last_total == 0) { + // First call, just set the last values + last_used = used; + last_total = total; + // return 0 since we have no data, not -1 which indicates error + return 0; + } + + jlong used_delta = used - last_used; + jlong total_delta = total - last_total; + + jdouble cpu = (jdouble) used_delta / total_delta; + + last_used = used; + last_total = total; + + return cpu; } + +#define TIME_VALUE_TO_TIMEVAL(a, r) do { \ + (r)->tv_sec = (a)->seconds; \ + (r)->tv_usec = (a)->microseconds; \ +} while (0) + + +#define TIME_VALUE_TO_MICROSECONDS(TV) \ + ((TV).tv_sec * 1000 * 1000 + (TV).tv_usec) + + JNIEXPORT jdouble JNICALL Java_com_sun_management_UnixOperatingSystem_getProcessCpuLoad (JNIEnv *env, jobject dummy) { - return -1.0; // not available -} + // This code is influenced by the darwin top source + + struct task_basic_info_64 task_info_data; + struct task_thread_times_info thread_info_data; + struct timeval user_timeval, system_timeval, task_timeval; + struct timeval now; + mach_port_t task = mach_task_self(); + kern_return_t kr; + + static jlong last_task_time = 0; + static jlong last_time = 0; + + mach_msg_type_number_t thread_info_count = TASK_THREAD_TIMES_INFO_COUNT; + kr = task_info(task, + TASK_THREAD_TIMES_INFO, + (task_info_t)&thread_info_data, + &thread_info_count); + if (kr != KERN_SUCCESS) { + // Most likely cause: |task| is a zombie. + return -1; + } + + mach_msg_type_number_t count = TASK_BASIC_INFO_64_COUNT; + kr = task_info(task, + TASK_BASIC_INFO_64, + (task_info_t)&task_info_data, + &count); + if (kr != KERN_SUCCESS) { + // Most likely cause: |task| is a zombie. + return -1; + } + + /* Set total_time. */ + // thread info contains live time... + TIME_VALUE_TO_TIMEVAL(&thread_info_data.user_time, &user_timeval); + TIME_VALUE_TO_TIMEVAL(&thread_info_data.system_time, &system_timeval); + timeradd(&user_timeval, &system_timeval, &task_timeval); + + // ... task info contains terminated time. + TIME_VALUE_TO_TIMEVAL(&task_info_data.user_time, &user_timeval); + TIME_VALUE_TO_TIMEVAL(&task_info_data.system_time, &system_timeval); + timeradd(&user_timeval, &task_timeval, &task_timeval); + timeradd(&system_timeval, &task_timeval, &task_timeval); + + if (gettimeofday(&now, NULL) < 0) { + return -1; + } + jint ncpus = JVM_ActiveProcessorCount(); + jlong time = TIME_VALUE_TO_MICROSECONDS(now) * ncpus; + jlong task_time = TIME_VALUE_TO_MICROSECONDS(task_timeval); + + if ((last_task_time == 0) || (last_time == 0)) { + // First call, just set the last values. + last_task_time = task_time; + last_time = time; + // return 0 since we have no data, not -1 which indicates error + return 0; + } + + jlong task_time_delta = task_time - last_task_time; + jlong time_delta = time - last_time; + if (time_delta == 0) { + return -1; + } + + jdouble cpu = (jdouble) task_time_delta / time_delta; + + last_task_time = task_time; + last_time = time; + + return cpu; + } diff --git a/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c b/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c index 088b3cfe809a584dc692a0e0b700884c28a59bc0..656306c83b64557eba1c1dfa6f0057a026450f36 100644 --- a/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c +++ b/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c @@ -34,6 +34,13 @@ #include #if defined(_ALLBSD_SOURCE) #include +#ifdef __APPLE__ +#include +#include +#include +#include +#include +#endif #else #include #endif @@ -150,6 +157,13 @@ static jlong get_total_or_available_swap_space_size(JNIEnv* env, jboolean availa avail = (jlong)si.freeswap * si.mem_unit; return available ? avail : total; +#elif defined(__APPLE__) + struct xsw_usage vmusage; + size_t size = sizeof(vmusage); + if (sysctlbyname("vm.swapusage", &vmusage, &size, NULL, 0) != 0) { + throw_internal_error(env, "sysctlbyname failed"); + } + return available ? (jlong)vmusage.xsu_avail : (jlong)vmusage.xsu_total; #else /* _ALLBSD_SOURCE */ /* * XXXBSD: there's no way available to get swap info in @@ -216,6 +230,15 @@ Java_com_sun_management_UnixOperatingSystem_getCommittedVirtualMemorySize fclose(fp); return (jlong)vsize; +#elif defined(__APPLE__) + struct task_basic_info t_info; + mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT; + + kern_return_t res = task_info(mach_task_self(), TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count); + if (res != KERN_SUCCESS) { + throw_internal_error(env, "task_info failed"); + } + return t_info.virtual_size; #else /* _ALLBSD_SOURCE */ /* * XXXBSD: there's no way available to do it in FreeBSD, AFAIK. @@ -243,6 +266,17 @@ JNIEXPORT jlong JNICALL Java_com_sun_management_UnixOperatingSystem_getProcessCpuTime (JNIEnv *env, jobject mbean) { +#ifdef __APPLE__ + struct rusage usage; + if (getrusage(RUSAGE_SELF, &usage) != 0) { + throw_internal_error(env, "getrusage failed"); + return -1; + } + jlong microsecs = + usage.ru_utime.tv_sec * 1000 * 1000 + usage.ru_utime.tv_usec + + usage.ru_stime.tv_sec * 1000 * 1000 + usage.ru_stime.tv_usec; + return microsecs * 1000; +#else jlong clk_tck, ns_per_clock_tick; jlong cpu_time_ns; struct tms time; @@ -267,19 +301,32 @@ Java_com_sun_management_UnixOperatingSystem_getProcessCpuTime cpu_time_ns = ((jlong)time.tms_utime + (jlong) time.tms_stime) * ns_per_clock_tick; return cpu_time_ns; +#endif } JNIEXPORT jlong JNICALL Java_com_sun_management_UnixOperatingSystem_getFreePhysicalMemorySize (JNIEnv *env, jobject mbean) { -#ifdef _ALLBSD_SOURCE +#ifdef __APPLE__ + mach_msg_type_number_t count; + vm_statistics_data_t vm_stats; + kern_return_t res; + + count = HOST_VM_INFO_COUNT; + res = host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vm_stats, &count); + if (res != KERN_SUCCESS) { + throw_internal_error(env, "host_statistics failed"); + return -1; + } + return (jlong)vm_stats.free_count * page_size; +#elif defined(_ALLBSD_SOURCE) /* * XXBSDL no way to do it in FreeBSD */ // throw_internal_error(env, "unimplemented in FreeBSD") return (128 * MB); -#else +#else // solaris / linux jlong num_avail_physical_pages = sysconf(_SC_AVPHYS_PAGES); return (num_avail_physical_pages * page_size); #endif @@ -290,28 +337,75 @@ Java_com_sun_management_UnixOperatingSystem_getTotalPhysicalMemorySize (JNIEnv *env, jobject mbean) { #ifdef _ALLBSD_SOURCE - jlong result; + jlong result = 0; int mib[2]; size_t rlen; mib[0] = CTL_HW; - mib[1] = HW_PHYSMEM; + mib[1] = HW_MEMSIZE; rlen = sizeof(result); - if (sysctl(mib, 2, &result, &rlen, NULL, 0) == -1) - result = 256 * MB; - - return (result); -#else + if (sysctl(mib, 2, &result, &rlen, NULL, 0) != 0) { + throw_internal_error(env, "sysctl failed"); + return -1; + } + return result; +#else // solaris / linux jlong num_physical_pages = sysconf(_SC_PHYS_PAGES); return (num_physical_pages * page_size); #endif } + + JNIEXPORT jlong JNICALL Java_com_sun_management_UnixOperatingSystem_getOpenFileDescriptorCount (JNIEnv *env, jobject mbean) { -#ifdef _ALLBSD_SOURCE +#ifdef __APPLE__ + // This code is influenced by the darwin lsof source + pid_t my_pid; + struct proc_bsdinfo bsdinfo; + struct proc_fdinfo *fds; + int nfiles; + kern_return_t kres; + int res; + size_t fds_size; + + kres = pid_for_task(mach_task_self(), &my_pid); + if (res != KERN_SUCCESS) { + throw_internal_error(env, "pid_for_task failed"); + return -1; + } + + // get the maximum number of file descriptors + res = proc_pidinfo(my_pid, PROC_PIDTBSDINFO, 0, &bsdinfo, PROC_PIDTBSDINFO_SIZE); + if (res <= 0) { + throw_internal_error(env, "proc_pidinfo with PROC_PIDTBSDINFO failed"); + return -1; + } + + // allocate memory to hold the fd information (we don't acutally use this information + // but need it to get the number of open files) + fds_size = bsdinfo.pbi_nfiles * sizeof(struct proc_fdinfo); + fds = malloc(fds_size); + if (fds == NULL) { + JNU_ThrowOutOfMemoryError(env, "could not allocate space for file descriptors"); + return -1; + } + + // get the list of open files - the return value is the number of bytes + // proc_pidinfo filled in + res = proc_pidinfo(my_pid, PROC_PIDLISTFDS, 0, fds, fds_size); + if (res <= 0) { + free(fds); + throw_internal_error(env, "proc_pidinfo failed for PROC_PIDLISTFDS"); + return -1; + } + nfiles = res / sizeof(struct proc_fdinfo); + free(fds); + + return nfiles; +#elif defined(_ALLBSD_SOURCE) /* * XXXBSD: there's no way available to do it in FreeBSD, AFAIK. */ diff --git a/test/ProblemList.txt b/test/ProblemList.txt index 94db829ba113e7a4734a86387f378f73230cfd99..1980d033038fe9ca3da325d49a224cf15e1ba578 100644 --- a/test/ProblemList.txt +++ b/test/ProblemList.txt @@ -161,6 +161,26 @@ demo/jvmti/compiledMethodLoad/CompiledMethodLoadTest.java generic-all # Need to be marked othervm, or changed to be samevm safe com/sun/jndi/rmi/registry/RegistryContext/UnbindIdempotent.java generic-all +# 7162111 +demo/jvmti/mtrace/TraceJFrame.java macosx-all +javax/script/CauseExceptionTest.java macosx-all +javax/script/GetInterfaceTest.java macosx-all +javax/script/JavaScriptScopeTest.java macosx-all +javax/script/NullUndefinedVarTest.java macosx-all +javax/script/PluggableContextTest.java macosx-all +javax/script/ProviderTest.sh macosx-all +javax/script/RhinoExceptionTest.java macosx-all +javax/script/StringWriterPrintTest.java macosx-all +javax/script/Test1.java macosx-all +javax/script/Test2.java macosx-all +javax/script/Test3.java macosx-all +javax/script/Test4.java macosx-all +javax/script/Test5.java macosx-all +javax/script/Test6.java macosx-all +javax/script/Test7.java macosx-all +javax/script/Test8.java macosx-all +javax/script/UnescapedBracketRegExTest.java macosx-all +javax/script/VersionTest.java macosx-all ############################################################################ # jdk_net @@ -202,6 +222,8 @@ java/net/DatagramSocket/SendDatagramToBadAddress.java macosx-all sun/net/www/protocol/http/B6299712.java macosx-all java/net/CookieHandler/CookieManagerTest.java macosx-all +# JPRT needs to set 127.0.0.1 in proxy bypass list +java/net/URLClassLoader/closetest/CloseTest.java macosx-all ############################################################################ # jdk_io diff --git a/test/com/sun/management/OperatingSystemMXBean/TestTotalSwap.sh b/test/com/sun/management/OperatingSystemMXBean/TestTotalSwap.sh index 63bff977ea8df81822df38dd7534e93c6bcf066a..009be0034eb0ab7dfaea60bd1e09737ae87f4043 100644 --- a/test/com/sun/management/OperatingSystemMXBean/TestTotalSwap.sh +++ b/test/com/sun/management/OperatingSystemMXBean/TestTotalSwap.sh @@ -83,6 +83,13 @@ case `uname -s` in total_swap=`free -b | grep -i swap | awk '{print $2}'` runOne GetTotalSwapSpaceSize $total_swap ;; + Darwin ) + # $ sysctl -n vm.swapusage + # total = 8192.00M used = 7471.11M free = 720.89M (encrypted) + swap=`/usr/sbin/sysctl -n vm.swapusage | awk '{ print $3 }' | awk -F . '{ print $1 }'` || exit 2 + total_swap=`expr $swap \* 1024 \* 1024` || exit 2 + runOne GetTotalSwapSpaceSize $total_swap + ;; * ) runOne GetTotalSwapSpaceSize "sanity-only" ;; diff --git a/test/java/lang/SecurityManager/CheckPackageAccess.java b/test/java/lang/SecurityManager/CheckPackageAccess.java new file mode 100644 index 0000000000000000000000000000000000000000..6db95eb3261b977c8331ac7887a5982f65256468 --- /dev/null +++ b/test/java/lang/SecurityManager/CheckPackageAccess.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 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 + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7146431 + * @summary Test that internal JAXP packages cannot be accessed + */ + +public class CheckPackageAccess { + + public static void main(String[] args) throws Exception { + + String[] pkgs = new String[] { + "com.sun.org.apache.xerces.internal.utils.", + "com.sun.org.apache.xalan.internal.utils." }; + SecurityManager sm = new SecurityManager(); + System.setSecurityManager(sm); + for (String pkg : pkgs) { + System.out.println("Checking package access for " + pkg); + try { + sm.checkPackageAccess(pkg); + throw new Exception("Expected SecurityException not thrown"); + } catch (SecurityException se) { } + } + } +} diff --git a/test/java/nio/charset/coders/StreamTimeout.java b/test/java/nio/charset/coders/StreamTimeout.java index 6511955dcbbd1e847ccc56e362c9dcbe0eff8d33..1d8f1175c3238c2193e19e86121682c93ff24448 100644 --- a/test/java/nio/charset/coders/StreamTimeout.java +++ b/test/java/nio/charset/coders/StreamTimeout.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2010, 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 @@ -27,51 +27,56 @@ * when the underlying byte stream times out */ -import java.net.*; -import java.io.*; - +import java.io.Closeable; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.InterruptedIOException; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.Reader; +import java.io.Writer; +import java.net.ServerSocket; +import java.net.Socket; public class StreamTimeout { + static final PrintStream log = System.err; + static String charset = "US-ASCII"; - private static PrintStream log = System.err; - - private static String charset = "US-ASCII"; + private static class Client extends Thread implements Closeable { + private final Socket so; - private static Object lock = new Object(); - private static synchronized void waitABit(int millisec) { - synchronized(lock) { - try { - lock.wait(millisec); - } catch (InterruptedException e) { - //ignore - } + Client(int port) throws IOException { + so = new Socket("127.0.0.1", port); } - } - private static class Client extends Thread { + @Override public void run() { try { - Socket so = new Socket("127.0.0.1", 22222); Writer wr = new OutputStreamWriter(so.getOutputStream(), - charset); + charset); wr.write("ab"); wr.flush(); } catch (IOException x) { log.print("Unexpected exception in writer: "); x.printStackTrace(); - System.exit(1); } } + + @Override + public void close() throws IOException { + so.close(); + } } private static void gobble(InputStream is, Reader rd, - int ec, boolean force) - throws Exception - { + int ec, boolean force) + throws Exception + { int a = is.available(); boolean r = rd.ready(); log.print("" + a + " bytes available, " - + "reader " + (r ? "" : "not ") + "ready"); + + "reader " + (r ? "" : "not ") + "ready"); if (!r && !force) { log.println(); return; @@ -84,10 +89,10 @@ public class StreamTimeout { throw x; } log.println(", read() ==> " - + (c >= 0 ? ("'" + (char)c + "'" ): "EOF")); + + (c >= 0 ? ("'" + (char)c + "'" ): "EOF")); if (c != ec) throw new Exception("Incorrect value read: Expected " - + ec + ", read " + (char)c); + + ec + ", read " + (char)c); } public static void main(String[] args) throws Exception { @@ -95,43 +100,49 @@ public class StreamTimeout { if (args.length > 0) charset = args[0]; - ServerSocket ss = new ServerSocket(22222); - Thread cl = new Client(); - cl.start(); - Socket s = ss.accept(); - s.setSoTimeout(150); - InputStream is = s.getInputStream(); - Reader rd = new InputStreamReader(is, charset); - - while (is.available() <= 0) - Thread.yield(); - - gobble(is, rd, 'a', false); - gobble(is, rd, 'b', false); - gobble(is, rd, -1, false); - - boolean caught = false; - try { - gobble(is, rd, -1, true); - } catch (InterruptedIOException e) { - log.println("Read timed out, as expected"); - caught = true; - } - if (!caught) { - log.println("Read did not time out, test inapplicable"); - return; - } + try(ServerSocket ss = new ServerSocket(0); + Client cl = new Client(ss.getLocalPort())) { + + cl.start(); + + try(Socket s = ss.accept()) { + s.setSoTimeout(150); + + try(InputStream is = s.getInputStream(); + Reader rd = new InputStreamReader(is, charset)) { + + while (is.available() <= 0) + Thread.yield(); + + gobble(is, rd, 'a', false); + gobble(is, rd, 'b', false); + gobble(is, rd, -1, false); + + boolean caught = false; + try { + gobble(is, rd, -1, true); + } catch (InterruptedIOException e) { + log.println("Read timed out, as expected"); + caught = true; + } + if (!caught) { + log.println("Read did not time out, test inapplicable"); + return; + } + + caught = false; + try { + gobble(is, rd, -1, true); + } catch (InterruptedIOException x) { + log.println("Second read timed out, as expected"); + caught = true; + } + if (!caught) + throw new Exception("Second read completed"); + } + } - caught = false; - try { - gobble(is, rd, -1, true); - } catch (InterruptedIOException x) { - log.println("Second read timed out, as expected"); - caught = true; + cl.join(); } - if (!caught) - throw new Exception("Second read completed"); - } - } diff --git a/test/sun/net/www/protocol/jar/B4957695.java b/test/sun/net/www/protocol/jar/B4957695.java index da1ee0e51f0e29fbb8ddb2f15ee45faa4d740a5c..0d25825f0cc6b022bf4aab2c7b2398739a8a981a 100644 --- a/test/sun/net/www/protocol/jar/B4957695.java +++ b/test/sun/net/www/protocol/jar/B4957695.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2003, 2006, 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 @@ -24,8 +24,6 @@ /** * @test * @bug 4957695 - * @library ../../httptest/ - * @build HttpCallback HttpServer ClosedChannelList HttpTransaction AbstractCallback * @summary URLJarFile.retrieve does not delete tmpFile on IOException */ @@ -34,43 +32,72 @@ import java.net.*; public class B4957695 { - static int count = 0; - static boolean error = false; + static Server server; - static void read (InputStream is) throws IOException { - int c,len=0; - while ((c=is.read()) != -1) { - len += c; + static class Server extends Thread { + final ServerSocket srv; + static final byte[] requestEnd = new byte[] {'\r', '\n', '\r', '\n'}; + + Server(ServerSocket s) { + srv = s; } - System.out.println ("read " + len + " bytes"); - } - static class CallBack extends AbstractCallback { + void readOneRequest(InputStream is) throws IOException { + int requestEndCount = 0, r; + while ((r = is.read()) != -1) { + if (r == requestEnd[requestEndCount]) { + requestEndCount++; + if (requestEndCount == 4) { + break; + } + } else { + requestEndCount = 0; + } + } + } + + public void run() { + try (Socket s = srv.accept()) { + // read HTTP request from client + readOneRequest(s.getInputStream()); + try (OutputStreamWriter ow = + new OutputStreamWriter((s.getOutputStream()))) { + FileInputStream fin = new FileInputStream("foo1.jar"); + int length = fin.available(); + byte[] b = new byte[length-10]; + fin.read(b, 0, length-10); + ow.write("HTTP/1.0 200 OK\r\n"); + + // Note: The client expects length bytes. + ow.write("Content-Length: " + length + "\r\n"); + ow.write("Content-Type: text/html\r\n"); + ow.write("\r\n"); - public void request (HttpTransaction req, int count) { - try { - System.out.println ("Request received"); - req.setResponseEntityBody (new FileInputStream ("foo1.jar")); - System.out.println ("content length " + req.getResponseHeader ( - "Content-length" - )); - req.sendPartialResponse (200, "Ok"); - req.abortiveClose(); + // Note: The (buggy) server only sends length-10 bytes. + ow.write(new String(b)); + ow.flush(); + } } catch (IOException e) { e.printStackTrace(); } } + } - }; - - static HttpServer server; + static void read (InputStream is) throws IOException { + int c,len=0; + while ((c=is.read()) != -1) { + len += c; + } + System.out.println ("read " + len + " bytes"); + } public static void main (String[] args) throws Exception { String tmpdir = System.getProperty("java.io.tmpdir"); String[] list1 = listTmpFiles(tmpdir); - //server = new HttpServer (new CallBack(), 10, 1, 0); - server = new HttpServer (new CallBack(), 1, 5, 0); - int port = server.getLocalPort(); + ServerSocket serverSocket = new ServerSocket(0); + server = new Server(serverSocket); + server.start(); + int port = serverSocket.getLocalPort(); System.out.println ("Server: listening on port: " + port); URL url = new URL ("jar:http://localhost:"+port+"!/COPYRIGHT"); try { @@ -81,14 +108,12 @@ public class B4957695 { } catch (IOException e) { System.out.println ("Received IOException as expected"); } - server.terminate(); String[] list2 = listTmpFiles(tmpdir); if (!sameList (list1, list2)) { throw new RuntimeException ("some jar_cache files left behind"); } } - static String[] listTmpFiles (String d) { File dir = new File (d); return dir.list (new FilenameFilter () {