JDK 9 RFR of JDK-8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
Joe Darcy
joe.darcy at oracle.com
Tue Jan 7 23:58:12 UTC 2014
Hello,
Please review the fix below to address
JDK-8031369: Fix raw types warnings in sun.misc.{Cache, SoftCache}
by a quick-and-dirty generification and deprecation of some very old classes
http://cr.openjdk.java.net/~darcy/8031369.0/
Corresponding patch below.
In the fullness of time, these classes should probably be removed from
the platform, but for the moment I'm more concerned with eliminating the
several dozen lint warnings in this code.
Thanks,
-Joe
--- old/src/share/classes/sun/misc/Cache.java 2014-01-07
15:51:32.000000000 -0800
+++ new/src/share/classes/sun/misc/Cache.java 2014-01-07
15:51:32.000000000 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1995, 1996, Oracle and/or its affiliates. All rights
reserved.
+ * Copyright (c) 1995, 2014, 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
@@ -74,8 +74,9 @@
* @see java.lang.Object#equals
* @see sun.misc.Ref
*/
+ at Deprecated
public
-class Cache extends Dictionary {
+ class Cache extends Dictionary<Object, Object> {
/**
* The hash table data.
*/
@@ -163,7 +164,7 @@
* @see Cache#elements
* @see Enumeration
*/
- public synchronized Enumeration keys() {
+ public synchronized Enumeration<Object> keys() {
return new CacheEnumerator(table, true);
}
@@ -173,7 +174,7 @@
* @see Cache#keys
* @see Enumeration
*/
- public synchronized Enumeration elements() {
+ public synchronized Enumeration<Object> elements() {
return new CacheEnumerator(table, false);
}
@@ -305,7 +306,7 @@
* A Cache enumerator class. This class should remain opaque
* to the client. It will use the Enumeration interface.
*/
-class CacheEnumerator implements Enumeration {
+class CacheEnumerator implements Enumeration<Object> {
boolean keys;
int index;
CacheEntry table[];
--- old/src/share/classes/sun/misc/SoftCache.java 2014-01-07
15:51:33.000000000 -0800
+++ new/src/share/classes/sun/misc/SoftCache.java 2014-01-07
15:51:33.000000000 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights
reserved.
+ * Copyright (c) 1998, 2014, 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
@@ -101,8 +101,8 @@
* @see java.lang.ref.SoftReference
*/
-
-public class SoftCache extends AbstractMap implements Map {
+ at Deprecated
+public class SoftCache extends AbstractMap<Object, Object> implements
Map<Object, Object> {
/* The basic idea of this implementation is to maintain an
internal HashMap
that maps keys to soft references whose referents are the keys'
values;
@@ -115,18 +115,18 @@
*/
- static private class ValueCell extends SoftReference {
+ static private class ValueCell extends SoftReference<Object> {
static private Object INVALID_KEY = new Object();
static private int dropped = 0;
private Object key;
- private ValueCell(Object key, Object value, ReferenceQueue queue) {
+ private ValueCell(Object key, Object value,
ReferenceQueue<Object> queue) {
super(value, queue);
this.key = key;
}
private static ValueCell create(Object key, Object value,
- ReferenceQueue queue)
+ ReferenceQueue<Object> queue)
{
if (value == null) return null;
return new ValueCell(key, value, queue);
@@ -154,10 +154,10 @@
/* Hash table mapping keys to ValueCells */
- private Map hash;
+ private Map<Object, Object> hash;
/* Reference queue for cleared ValueCells */
- private ReferenceQueue queue = new ReferenceQueue();
+ private ReferenceQueue<Object> queue = new ReferenceQueue<>();
/* Process any ValueCells that have been cleared and enqueued by the
@@ -189,7 +189,7 @@
* factor is less than zero
*/
public SoftCache(int initialCapacity, float loadFactor) {
- hash = new HashMap(initialCapacity, loadFactor);
+ hash = new HashMap<>(initialCapacity, loadFactor);
}
/**
@@ -202,7 +202,7 @@
* or equal to zero
*/
public SoftCache(int initialCapacity) {
- hash = new HashMap(initialCapacity);
+ hash = new HashMap<>(initialCapacity);
}
/**
@@ -210,7 +210,7 @@
* capacity and the default load factor.
*/
public SoftCache() {
- hash = new HashMap();
+ hash = new HashMap<>();
}
@@ -348,13 +348,13 @@
/* Internal class for entries.
Because it uses SoftCache.this.queue, this class cannot be static.
*/
- private class Entry implements Map.Entry {
- private Map.Entry ent;
+ private class Entry implements Map.Entry<Object, Object> {
+ private Map.Entry<Object, Object> ent;
private Object value; /* Strong reference to value, to
prevent the GC
from flushing the value while this
Entry
exists */
- Entry(Map.Entry ent, Object value) {
+ Entry(Map.Entry<Object, Object> ent, Object value) {
this.ent = ent;
this.value = value;
}
@@ -371,9 +371,10 @@
return ent.setValue(ValueCell.create(ent.getKey(), value,
queue));
}
+ @SuppressWarnings("unchecked")
public boolean equals(Object o) {
if (! (o instanceof Map.Entry)) return false;
- Map.Entry e = (Map.Entry)o;
+ Map.Entry<Object, Object> e = (Map.Entry<Object, Object>)o;
return (valEquals(ent.getKey(), e.getKey())
&& valEquals(value, e.getValue()));
}
@@ -388,18 +389,18 @@
/* Internal class for entry sets */
- private class EntrySet extends AbstractSet {
- Set hashEntries = hash.entrySet();
+ private class EntrySet extends AbstractSet<Map.Entry<Object, Object>> {
+ Set<Map.Entry<Object, Object>> hashEntries = hash.entrySet();
- public Iterator iterator() {
+ public Iterator<Map.Entry<Object, Object>> iterator() {
- return new Iterator() {
- Iterator hashIterator = hashEntries.iterator();
+ return new Iterator<Map.Entry<Object, Object>>() {
+ Iterator<Map.Entry<Object, Object>> hashIterator =
hashEntries.iterator();
Entry next = null;
public boolean hasNext() {
while (hashIterator.hasNext()) {
- Map.Entry ent = (Map.Entry)hashIterator.next();
+ Map.Entry<Object, Object> ent =
hashIterator.next();
ValueCell vc = (ValueCell)ent.getValue();
Object v = null;
if ((vc != null) && ((v = vc.get()) == null)) {
@@ -412,7 +413,7 @@
return false;
}
- public Object next() {
+ public Map.Entry<Object, Object> next() {
if ((next == null) && !hasNext())
throw new NoSuchElementException();
Entry e = next;
@@ -433,7 +434,7 @@
public int size() {
int j = 0;
- for (Iterator i = iterator(); i.hasNext(); i.next()) j++;
+ for (Iterator<Map.Entry<Object, Object>> i = iterator();
i.hasNext(); i.next()) j++;
return j;
}
@@ -446,12 +447,12 @@
}
- private Set entrySet = null;
+ private Set<Map.Entry<Object, Object>> entrySet = null;
/**
* Return a <code>Set</code> view of the mappings in this cache.
*/
- public Set entrySet() {
+ public Set<Map.Entry<Object, Object>> entrySet() {
if (entrySet == null) entrySet = new EntrySet();
return entrySet;
}
More information about the core-libs-dev
mailing list