JDK 9 RFR of JDK-8054050: Fix stay raw and unchecked lint warnings in core libs
Lance Andersen
lance.andersen at oracle.com
Thu Jul 31 18:01:05 UTC 2014
looks fine joe
On Jul 31, 2014, at 1:57 PM, Joe Darcy <joe.darcy at oracle.com> wrote:
> Hello,
>
> There are a few stray raw and unchecked warnings remaining in core libs; please review my fix:
>
> JDK-8054050: Fix stay raw and unchecked lint warnings in core libs
> http://cr.openjdk.java.net/~darcy/8054050.0/
>
> Patch below.
>
> Thanks,
>
> -Joe
>
> --- old/src/share/classes/com/sun/management/GcInfo.java 2014-07-31 10:51:14.000000000 -0700
> +++ new/src/share/classes/com/sun/management/GcInfo.java 2014-07-31 10:51:14.000000000 -0700
> @@ -267,7 +267,7 @@
> return cdata.toString();
> }
>
> - public Collection values() {
> + public Collection<?> values() {
> return cdata.values();
> }
>
> --- old/src/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java 2014-07-31 10:51:14.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/example/debug/expr/ExpressionParser.java 2014-07-31 10:51:14.000000000 -0700
> @@ -33,18 +33,18 @@
>
> public class ExpressionParser implements ExpressionParserConstants {
>
> - Stack stack = new Stack();
> + Stack<LValue> stack = new Stack<>();
> VirtualMachine vm = null;
> GetFrame frameGetter = null;
> private static GetFrame lastFrameGetter;
> private static LValue lastLValue;
>
> LValue peek() {
> - return (LValue)stack.peek();
> + return stack.peek();
> }
>
> LValue pop() {
> - return (LValue)stack.pop();
> + return stack.pop();
> }
>
> void push(LValue lval) {
> @@ -915,7 +915,7 @@
> }
>
> final public void PrimarySuffix() throws ParseException {
> - List argList;
> + List<Value> argList;
> switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
> case LBRACKET:
> jj_consume_token(LBRACKET);
> @@ -993,8 +993,8 @@
> jj_consume_token(NULL);
> }
>
> - final public List Arguments() throws ParseException {
> - List argList = new ArrayList();
> + final public List<Value> Arguments() throws ParseException {
> + List<Value> argList = new ArrayList<>();
> jj_consume_token(LPAREN);
> switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
> case FALSE:
> @@ -1026,7 +1026,7 @@
> throw new Error("Missing return statement in function");
> }
>
> - final public void ArgumentList(List argList) throws ParseException {
> + final public void ArgumentList(List<Value> argList) throws ParseException {
> Expression();
> argList.add(pop().interiorGetValue());
> label_17:
> @@ -1046,7 +1046,7 @@
> }
>
> final public void AllocationExpression() throws ParseException {
> - List argList; String className;
> + List<Value> argList; String className;
> if (jj_2_7(2)) {
> jj_consume_token(NEW);
> PrimitiveType();
> --- old/src/share/classes/com/sun/tools/hat/internal/model/JavaClass.java 2014-07-31 10:51:15.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/model/JavaClass.java 2014-07-31 10:51:15.000000000 -0700
> @@ -229,9 +229,9 @@
> return name.indexOf('[') != -1;
> }
>
> - public Enumeration getInstances(boolean includeSubclasses) {
> + public Enumeration<JavaHeapObject> getInstances(boolean includeSubclasses) {
> if (includeSubclasses) {
> - Enumeration res = instances.elements();
> + Enumeration<JavaHeapObject> res = instances.elements();
> for (int i = 0; i < subclasses.length; i++) {
> res = new CompositeEnumeration(res,
> subclasses[i].getInstances(true));
> --- old/src/share/classes/com/sun/tools/hat/internal/model/JavaHeapObject.java 2014-07-31 10:51:15.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/model/JavaHeapObject.java 2014-07-31 10:51:15.000000000 -0700
> @@ -166,11 +166,11 @@
> *
> * @return an Enumeration of JavaHeapObject instances
> */
> - public Enumeration getReferers() {
> + public Enumeration<JavaThing> getReferers() {
> if (referersLen != -1) {
> throw new RuntimeException("not resolved: " + getIdString());
> }
> - return new Enumeration() {
> + return new Enumeration<JavaThing>() {
>
> private int num = 0;
>
> @@ -178,7 +178,7 @@
> return referers != null && num < referers.length;
> }
>
> - public Object nextElement() {
> + public JavaThing nextElement() {
> return referers[num++];
> }
> };
> --- old/src/share/classes/com/sun/tools/hat/internal/model/ReachableExcludesImpl.java 2014-07-31 10:51:16.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/model/ReachableExcludesImpl.java 2014-07-31 10:51:16.000000000 -0700
> @@ -54,7 +54,7 @@
>
> private File excludesFile;
> private long lastModified;
> - private Hashtable methods; // Hashtable<String, String>, used as a bag
> + private Hashtable<String, String> methods; // Used as a bag
>
> /**
> * Create a new ReachableExcludesImpl over the given file. The file will be
> --- old/src/share/classes/com/sun/tools/hat/internal/model/ReachableObjects.java 2014-07-31 10:51:16.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/model/ReachableObjects.java 2014-07-31 10:51:16.000000000 -0700
> @@ -86,7 +86,7 @@
> // Now grab the elements into a vector, and sort it in decreasing size
> JavaThing[] things = new JavaThing[bag.size()];
> int i = 0;
> - for (Enumeration e = bag.elements(); e.hasMoreElements(); ) {
> + for (Enumeration<JavaHeapObject> e = bag.elements(); e.hasMoreElements(); ) {
> things[i++] = (JavaThing) e.nextElement();
> }
> ArraySorter.sort(things, new Comparer() {
> @@ -131,7 +131,7 @@
> return usedFields;
> }
>
> - private String[] getElements(Hashtable ht) {
> + private String[] getElements(Hashtable<?, ?> ht) {
> Object[] keys = ht.keySet().toArray();
> int len = keys.length;
> String[] res = new String[len];
> --- old/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java 2014-07-31 10:51:17.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/model/Snapshot.java 2014-07-31 10:51:16.000000000 -0700
> @@ -81,7 +81,7 @@
> new HashMap<JavaHeapObject, Root>();
>
> // soft cache of finalizeable objects - lazily initialized
> - private SoftReference<Vector> finalizablesCache;
> + private SoftReference<Vector<?>> finalizablesCache;
>
> // represents null reference
> private JavaThing nullThing;
> @@ -383,7 +383,7 @@
> /**
> * Return an Iterator of all of the classes in this snapshot.
> **/
> - public Iterator getClasses() {
> + public Iterator<JavaClass> getClasses() {
> // note that because classes is a TreeMap
> // classes are already sorted by name
> return classes.values().iterator();
> @@ -395,8 +395,8 @@
> return res;
> }
>
> - public synchronized Enumeration getFinalizerObjects() {
> - Vector obj;
> + public synchronized Enumeration<?> getFinalizerObjects() {
> + Vector<?> obj;
> if (finalizablesCache != null &&
> (obj = finalizablesCache.get()) != null) {
> return obj.elements();
> @@ -418,7 +418,7 @@
> finalizables.add(referent);
> }
> }
> - finalizablesCache = new SoftReference<Vector>(finalizables);
> + finalizablesCache = new SoftReference<Vector<?>>(finalizables);
> return finalizables.elements();
> }
>
> @@ -455,7 +455,7 @@
> // Even though curr is in the rootset, we want to explore its
> // referers, because they might be more interesting.
> }
> - Enumeration referers = curr.getReferers();
> + Enumeration<JavaThing> referers = curr.getReferers();
> while (referers.hasMoreElements()) {
> JavaHeapObject t = (JavaHeapObject) referers.nextElement();
> if (t != null && !visited.containsKey(t)) {
> --- old/src/share/classes/com/sun/tools/hat/internal/oql/OQLEngine.java 2014-07-31 10:51:17.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/oql/OQLEngine.java 2014-07-31 10:51:17.000000000 -0700
> @@ -51,7 +51,7 @@
>
> // create JavaScript engine
> Method getEngineMethod = managerClass.getMethod("getEngineByName",
> - new Class[] { String.class });
> + new Class<?>[] { String.class });
> Object jse = getEngineMethod.invoke(manager, new Object[] {"js"});
> oqlSupported = (jse != null);
> } catch (Exception exp) {
> @@ -205,9 +205,9 @@
> }
>
> if (q.className != null) {
> - Enumeration objects = clazz.getInstances(q.isInstanceOf);
> + Enumeration<JavaHeapObject> objects = clazz.getInstances(q.isInstanceOf);
> while (objects.hasMoreElements()) {
> - JavaHeapObject obj = (JavaHeapObject) objects.nextElement();
> + JavaHeapObject obj = objects.nextElement();
> Object[] args = new Object[] { wrapJavaObject(obj) };
> boolean b = (whereCode == null);
> if (!b) {
> @@ -265,14 +265,14 @@
>
> // create JavaScript engine
> Method getEngineMethod = managerClass.getMethod("getEngineByName",
> - new Class[] { String.class });
> + new Class<?>[] { String.class });
> engine = getEngineMethod.invoke(manager, new Object[] {"js"});
>
> // initialize engine with init file (hat.js)
> InputStream strm = getInitStream();
> Class<?> engineClass = Class.forName("javax.script.ScriptEngine");
> evalMethod = engineClass.getMethod("eval",
> - new Class[] { Reader.class });
> + new Class<?>[] { Reader.class });
> evalMethod.invoke(engine, new Object[] {new InputStreamReader(strm)});
>
> // initialize ScriptEngine.eval(String) and
> @@ -280,13 +280,13 @@
> Class<?> invocableClass = Class.forName("javax.script.Invocable");
>
> evalMethod = engineClass.getMethod("eval",
> - new Class[] { String.class });
> + new Class<?>[] { String.class });
> invokeMethod = invocableClass.getMethod("invokeFunction",
> - new Class[] { String.class, Object[].class });
> + new Class<?>[] { String.class, Object[].class });
>
> // initialize ScriptEngine.put(String, Object) method
> Method putMethod = engineClass.getMethod("put",
> - new Class[] { String.class, Object.class });
> + new Class<?>[] { String.class, Object.class });
>
> // call ScriptEngine.put to initialize built-in heap object
> putMethod.invoke(engine, new Object[] {
> --- old/src/share/classes/com/sun/tools/hat/internal/server/AllClassesQuery.java 2014-07-31 10:51:18.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/AllClassesQuery.java 2014-07-31 10:51:17.000000000 -0700
> @@ -58,10 +58,10 @@
> startHtml("All Classes (including platform)");
> }
>
> - Iterator classes = snapshot.getClasses();
> + Iterator<JavaClass> classes = snapshot.getClasses();
> String lastPackage = null;
> while (classes.hasNext()) {
> - JavaClass clazz = (JavaClass) classes.next();
> + JavaClass clazz = classes.next();
> if (excludePlatform && PlatformClasses.isPlatformClass(clazz)) {
> // skip this..
> continue;
> --- old/src/share/classes/com/sun/tools/hat/internal/server/ClassQuery.java 2014-07-31 10:51:18.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/ClassQuery.java 2014-07-31 10:51:18.000000000 -0700
> @@ -151,7 +151,7 @@
> }
> out.println("<h2>References to this object:</h2>");
> out.flush();
> - Enumeration referers = obj.getReferers();
> + Enumeration<JavaThing> referers = obj.getReferers();
> while (referers.hasMoreElements()) {
> JavaHeapObject ref = (JavaHeapObject) referers.nextElement();
> printThing(ref);
> --- old/src/share/classes/com/sun/tools/hat/internal/server/FinalizerObjectsQuery.java 2014-07-31 10:51:19.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/FinalizerObjectsQuery.java 2014-07-31 10:51:19.000000000 -0700
> @@ -37,7 +37,7 @@
>
> public class FinalizerObjectsQuery extends QueryHandler {
> public void run() {
> - Enumeration objs = snapshot.getFinalizerObjects();
> + Enumeration<?> objs = snapshot.getFinalizerObjects();
> startHtml("Objects pending finalization");
>
> out.println("<a href='/finalizerSummary/'>Finalizer summary</a>");
> --- old/src/share/classes/com/sun/tools/hat/internal/server/FinalizerSummaryQuery.java 2014-07-31 10:51:19.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/FinalizerSummaryQuery.java 2014-07-31 10:51:19.000000000 -0700
> @@ -37,7 +37,7 @@
>
> public class FinalizerSummaryQuery extends QueryHandler {
> public void run() {
> - Enumeration objs = snapshot.getFinalizerObjects();
> + Enumeration<?> objs = snapshot.getFinalizerObjects();
> startHtml("Finalizer Summary");
>
> out.println("<p align='center'>");
> @@ -74,7 +74,7 @@
> private long count;
> }
>
> - private void printFinalizerSummary(Enumeration objs) {
> + private void printFinalizerSummary(Enumeration<?> objs) {
> int count = 0;
> Map<JavaClass, HistogramElement> map = new HashMap<JavaClass, HistogramElement>();
>
> --- old/src/share/classes/com/sun/tools/hat/internal/server/InstancesCountQuery.java 2014-07-31 10:51:20.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/InstancesCountQuery.java 2014-07-31 10:51:20.000000000 -0700
> @@ -111,10 +111,10 @@
> }
> out.print("</a> ");
> if (snapshot.getHasNewSet()) {
> - Enumeration objects = clazz.getInstances(false);
> + Enumeration<JavaHeapObject> objects = clazz.getInstances(false);
> int newInst = 0;
> while (objects.hasMoreElements()) {
> - JavaHeapObject obj = (JavaHeapObject)objects.nextElement();
> + JavaHeapObject obj = objects.nextElement();
> if (obj.isNew()) {
> newInst++;
> }
> --- old/src/share/classes/com/sun/tools/hat/internal/server/InstancesQuery.java 2014-07-31 10:51:21.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/InstancesQuery.java 2014-07-31 10:51:20.000000000 -0700
> @@ -73,11 +73,11 @@
> out.print("<strong>");
> printClass(clazz);
> out.print("</strong><br><br>");
> - Enumeration objects = clazz.getInstances(includeSubclasses);
> + Enumeration<JavaHeapObject> objects = clazz.getInstances(includeSubclasses);
> long totalSize = 0;
> long instances = 0;
> while (objects.hasMoreElements()) {
> - JavaHeapObject obj = (JavaHeapObject) objects.nextElement();
> + JavaHeapObject obj = objects.nextElement();
> if (newObjects && !obj.isNew())
> continue;
> printThing(obj);
> --- old/src/share/classes/com/sun/tools/hat/internal/server/RefsByTypeQuery.java 2014-07-31 10:51:21.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/server/RefsByTypeQuery.java 2014-07-31 10:51:21.000000000 -0700
> @@ -47,15 +47,15 @@
> } else {
> Map<JavaClass, Long> referrersStat = new HashMap<JavaClass, Long>();
> final Map<JavaClass, Long> refereesStat = new HashMap<JavaClass, Long>();
> - Enumeration instances = clazz.getInstances(false);
> + Enumeration<JavaHeapObject> instances = clazz.getInstances(false);
> while (instances.hasMoreElements()) {
> - JavaHeapObject instance = (JavaHeapObject) instances.nextElement();
> + JavaHeapObject instance = instances.nextElement();
> if (instance.getId() == -1) {
> continue;
> }
> - Enumeration e = instance.getReferers();
> + Enumeration<JavaThing> e = instance.getReferers();
> while (e.hasMoreElements()) {
> - JavaHeapObject ref = (JavaHeapObject) e.nextElement();
> + JavaHeapObject ref = (JavaHeapObject)e.nextElement();
> JavaClass cl = ref.getClazz();
> if (cl == null) {
> System.out.println("null class for " + ref);
> --- old/src/share/classes/com/sun/tools/hat/internal/util/CompositeEnumeration.java 2014-07-31 10:51:22.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/hat/internal/util/CompositeEnumeration.java 2014-07-31 10:51:21.000000000 -0700
> @@ -34,12 +34,13 @@
>
> import java.util.Enumeration;
> import java.util.NoSuchElementException;
> +import com.sun.tools.hat.internal.model.JavaHeapObject;
>
> -public class CompositeEnumeration implements Enumeration {
> - Enumeration e1;
> - Enumeration e2;
> +public class CompositeEnumeration implements Enumeration<JavaHeapObject> {
> + Enumeration<JavaHeapObject> e1;
> + Enumeration<JavaHeapObject> e2;
>
> - public CompositeEnumeration(Enumeration e1, Enumeration e2) {
> + public CompositeEnumeration(Enumeration<JavaHeapObject> e1, Enumeration<JavaHeapObject> e2) {
> this.e1 = e1;
> this.e2 = e2;
> }
> @@ -48,7 +49,7 @@
> return e1.hasMoreElements() || e2.hasMoreElements();
> }
>
> - public Object nextElement() {
> + public JavaHeapObject nextElement() {
> if (e1.hasMoreElements()) {
> return e1.nextElement();
> }
> --- old/src/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java 2014-07-31 10:51:22.000000000 -0700
> +++ new/src/share/classes/com/sun/tools/jdi/EventRequestManagerImpl.java 2014-07-31 10:51:22.000000000 -0700
> @@ -39,7 +39,7 @@
> // Warnings from List filters and List[] requestLists is hard to fix.
> // Remove SuppressWarning when we fix the warnings from List filters
> // and List[] requestLists. The generic array is not supported.
> - at SuppressWarnings("unchecked")
> + at SuppressWarnings({"unchecked", "rawtypes"})
> class EventRequestManagerImpl extends MirrorImpl
> implements EventRequestManager
> {
> --- old/src/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java 2014-07-31 10:51:22.000000000 -0700
> +++ new/src/share/classes/jdk/nio/zipfs/ZipFileAttributeView.java 2014-07-31 10:51:22.000000000 -0700
> @@ -59,6 +59,7 @@
> this.isZipView = isZipView;
> }
>
> + @SuppressWarnings("unchecked") // Cast to V
> static <V extends FileAttributeView> V get(ZipPath path, Class<V> type) {
> if (type == null)
> throw new NullPointerException();
> --- old/src/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java 2014-07-31 10:51:23.000000000 -0700
> +++ new/src/share/classes/jdk/nio/zipfs/ZipFileSystemProvider.java 2014-07-31 10:51:23.000000000 -0700
> @@ -271,6 +271,7 @@
> }
>
> @Override
> + @SuppressWarnings("unchecked") // Cast to A
> public <A extends BasicFileAttributes> A
> readAttributes(Path path, Class<A> type, LinkOption... options)
> throws IOException
> --- old/src/solaris/classes/sun/nio/ch/InheritedChannel.java 2014-07-31 10:51:24.000000000 -0700
> +++ new/src/solaris/classes/sun/nio/ch/InheritedChannel.java 2014-07-31 10:51:23.000000000 -0700
> @@ -165,7 +165,7 @@
> // Have to use reflection and also make assumption on how FD
> // is implemented.
>
> - Class paramTypes[] = { int.class };
> + Class<?> paramTypes[] = { int.class };
> Constructor<?> ctr = Reflect.lookupConstructor("java.io.FileDescriptor",
> paramTypes);
> Object args[] = { new Integer(fdVal) };
>
Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20140731/47829ea7/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oracle_sig_logo.gif
Type: image/gif
Size: 658 bytes
Desc: not available
URL: <http://mail.openjdk.java.net/pipermail/serviceability-dev/attachments/20140731/47829ea7/oracle_sig_logo-0001.gif>
More information about the serviceability-dev
mailing list