7117357: Warnings in sun.instrument, tools and other sun.* classes
authoralanb
Fri, 02 Dec 2011 17:37:30 +0000
changeset 11125 99b115114fa3
parent 11124 5fdabdc21259
child 11126 00a6b63e7ba4
7117357: Warnings in sun.instrument, tools and other sun.* classes Reviewed-by: lancea, chegar
jdk/src/share/classes/sun/instrument/InstrumentationImpl.java
jdk/src/share/classes/sun/instrument/TransformerManager.java
jdk/src/share/classes/sun/launcher/LauncherHelper.java
jdk/src/share/classes/sun/management/counter/perf/PerfInstrumentation.java
jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java
jdk/src/share/classes/sun/net/RegisteredDomain.java
jdk/src/share/classes/sun/net/www/protocol/jar/Handler.java
jdk/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java
jdk/src/share/classes/sun/tools/jinfo/JInfo.java
jdk/src/share/classes/sun/tools/jmap/JMap.java
jdk/src/share/classes/sun/tools/jps/Jps.java
jdk/src/share/classes/sun/tools/jstack/JStack.java
jdk/src/share/classes/sun/tools/serialver/SerialVer.java
--- a/jdk/src/share/classes/sun/instrument/InstrumentationImpl.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/instrument/InstrumentationImpl.java	Fri Dec 02 17:37:30 2011 +0000
@@ -136,7 +136,7 @@
     }
 
     public void
-    retransformClasses(Class<?>[] classes) {
+    retransformClasses(Class<?>... classes) {
         if (!isRetransformClassesSupported()) {
             throw new UnsupportedOperationException(
               "retransformClasses is not supported in this environment");
@@ -150,7 +150,7 @@
     }
 
     public void
-    redefineClasses(ClassDefinition[]   definitions)
+    redefineClasses(ClassDefinition...  definitions)
             throws  ClassNotFoundException {
         if (!isRedefineClassesSupported()) {
             throw new UnsupportedOperationException("redefineClasses is not supported in this environment");
@@ -321,7 +321,7 @@
 
         try {
             m = javaAgentClass.getDeclaredMethod( methodname,
-                                 new Class[] {
+                                 new Class<?>[] {
                                      String.class,
                                      java.lang.instrument.Instrumentation.class
                                  }
@@ -336,7 +336,7 @@
             // now try the declared 1-arg method
             try {
                 m = javaAgentClass.getDeclaredMethod(methodname,
-                                                 new Class[] { String.class });
+                                                 new Class<?>[] { String.class });
             } catch (NoSuchMethodException x) {
                 // ignore this exception because we'll try
                 // two arg inheritance next
@@ -347,7 +347,7 @@
             // now try the inherited 2-arg method
             try {
                 m = javaAgentClass.getMethod( methodname,
-                                 new Class[] {
+                                 new Class<?>[] {
                                      String.class,
                                      java.lang.instrument.Instrumentation.class
                                  }
@@ -363,7 +363,7 @@
             // finally try the inherited 1-arg method
             try {
                 m = javaAgentClass.getMethod(methodname,
-                                             new Class[] { String.class });
+                                             new Class<?>[] { String.class });
             } catch (NoSuchMethodException x) {
                 // none of the methods exists so we throw the
                 // first NoSuchMethodException as per 5.0
@@ -411,7 +411,7 @@
     private byte[]
     transform(  ClassLoader         loader,
                 String              classname,
-                Class               classBeingRedefined,
+                Class<?>            classBeingRedefined,
                 ProtectionDomain    protectionDomain,
                 byte[]              classfileBuffer,
                 boolean             isRetransformer) {
--- a/jdk/src/share/classes/sun/instrument/TransformerManager.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/instrument/TransformerManager.java	Fri Dec 02 17:37:30 2011 +0000
@@ -169,7 +169,7 @@
     public byte[]
     transform(  ClassLoader         loader,
                 String              classname,
-                Class               classBeingRedefined,
+                Class<?>            classBeingRedefined,
                 ProtectionDomain    protectionDomain,
                 byte[]              classfileBuffer) {
         boolean someoneTouchedTheBytecode = false;
--- a/jdk/src/share/classes/sun/launcher/LauncherHelper.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/launcher/LauncherHelper.java	Fri Dec 02 17:37:30 2011 +0000
@@ -428,7 +428,7 @@
             if (t != null) {
                 t.printStackTrace();
             } else {
-                Thread.currentThread().dumpStack();
+                Thread.dumpStack();
             }
         }
         System.exit(1);
--- a/jdk/src/share/classes/sun/management/counter/perf/PerfInstrumentation.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/management/counter/perf/PerfInstrumentation.java	Fri Dec 02 17:37:30 2011 +0000
@@ -169,17 +169,15 @@
         Matcher matcher = pattern.matcher("");
         List<Counter> matches = new ArrayList<Counter>();
 
-        Iterator iter = map.entrySet().iterator();
-        while (iter.hasNext()) {
-            Map.Entry me = (Map.Entry) iter.next();
-            String name = (String) me.getKey();
+        for (Map.Entry<String,Counter> me: map.entrySet()) {
+            String name = me.getKey();
 
             // apply pattern to counter name
             matcher.reset(name);
 
             // if the pattern matches, then add Counter to list
             if (matcher.lookingAt()) {
-                matches.add((Counter)me.getValue());
+                matches.add(me.getValue());
             }
         }
         return matches;
--- a/jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java	Fri Dec 02 17:37:30 2011 +0000
@@ -233,16 +233,14 @@
                         "the access file [" + accessFile + "] as the " +
                         "authenticated Subject is null");
             }
-            final Set principals = subject.getPrincipals();
-            for (Iterator i = principals.iterator(); i.hasNext();) {
-                final Principal p = (Principal) i.next();
+            final Set<Principal> principals = subject.getPrincipals();
+            for (Principal p: principals) {
                 if (properties.containsKey(p.getName())) {
                     return;
                 }
             }
             final Set<String> principalsStr = new HashSet<String>();
-            for (Iterator i = principals.iterator(); i.hasNext();) {
-                final Principal p = (Principal) i.next();
+            for (Principal p: principals) {
                 principalsStr.add(p.getName());
             }
             throw new SecurityException(
@@ -653,7 +651,7 @@
                 }
                 TrustManagerFactory tmf = TrustManagerFactory.getInstance(
                         TrustManagerFactory.getDefaultAlgorithm());
-                tmf.init((KeyStore) ts);
+                tmf.init(ts);
 
                 SSLContext ctx = SSLContext.getInstance("SSL");
                 ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
--- a/jdk/src/share/classes/sun/net/RegisteredDomain.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/net/RegisteredDomain.java	Fri Dec 02 17:37:30 2011 +0000
@@ -118,8 +118,8 @@
 private static Set<String>  usSubStateSet = new HashSet<String>(Arrays.asList("state",
                 "lib", "k12", "cc", "tec", "gen", "cog", "mus", "dst"));
 
-private static Map<String,Set> topMap = new HashMap<String,Set>();
-private static Map<String,Set> top3Map = new HashMap<String,Set>();
+private static Map<String,Set<String>> topMap = new HashMap<>();
+private static Map<String,Set<String>> top3Map = new HashMap<>();
 
 static {
     /*
@@ -764,7 +764,7 @@
          */
         String str = cname.substring(third + 1);
         if (third != -1) {
-            Set set = top3Map.get(s);
+            Set<String> set = top3Map.get(s);
             if (set != null) {
                 if (set.contains(str)) {
                     return cname.substring(fourth + 1);
@@ -801,7 +801,7 @@
         /*
          * XX.MA.US.
          */
-        Set topSet = topMap.get(s);
+        Set<String> topSet = topMap.get(s);
         if (topSet != null) {
             if (topSet.contains(s2)) {
                 return cname.substring(third + 1);
--- a/jdk/src/share/classes/sun/net/www/protocol/jar/Handler.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/net/www/protocol/jar/Handler.java	Fri Dec 02 17:37:30 2011 +0000
@@ -123,6 +123,7 @@
 
 
     @Override
+    @SuppressWarnings("deprecation")
     protected void parseURL(URL url, String spec,
                             int start, int limit) {
         String file = null;
--- a/jdk/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java	Fri Dec 02 17:37:30 2011 +0000
@@ -75,7 +75,7 @@
             new ArrayList<VirtualMachineDescriptor>();
 
         MonitoredHost host;
-        Set vms;
+        Set<Integer> vms;
         try {
             host = MonitoredHost.getMonitoredHost(new HostIdentifier((String)null));
             vms = host.activeVms();
@@ -92,31 +92,29 @@
             throw new InternalError(t);          // shouldn't happen
         }
 
-        for (Object vmid: vms) {
-            if (vmid instanceof Integer) {
-                String pid = vmid.toString();
-                String name = pid;      // default to pid if name not available
-                boolean isAttachable = false;
-                MonitoredVm mvm = null;
+        for (Integer vmid: vms) {
+            String pid = vmid.toString();
+            String name = pid;      // default to pid if name not available
+            boolean isAttachable = false;
+            MonitoredVm mvm = null;
+            try {
+                mvm = host.getMonitoredVm(new VmIdentifier(pid));
                 try {
-                    mvm = host.getMonitoredVm(new VmIdentifier(pid));
-                    try {
-                        isAttachable = MonitoredVmUtil.isAttachable(mvm);
-                        // use the command line as the display name
-                        name =  MonitoredVmUtil.commandLine(mvm);
-                    } catch (Exception e) {
-                    }
-                    if (isAttachable) {
-                        result.add(new HotSpotVirtualMachineDescriptor(this, pid, name));
-                    }
-                } catch (Throwable t) {
-                    if (t instanceof ThreadDeath) {
-                        throw (ThreadDeath)t;
-                    }
-                } finally {
-                    if (mvm != null) {
-                        mvm.detach();
-                    }
+                    isAttachable = MonitoredVmUtil.isAttachable(mvm);
+                    // use the command line as the display name
+                    name =  MonitoredVmUtil.commandLine(mvm);
+                } catch (Exception e) {
+                }
+                if (isAttachable) {
+                    result.add(new HotSpotVirtualMachineDescriptor(this, pid, name));
+                }
+            } catch (Throwable t) {
+                if (t instanceof ThreadDeath) {
+                    throw (ThreadDeath)t;
+                }
+            } finally {
+                if (mvm != null) {
+                    mvm.detach();
                 }
             }
         }
--- a/jdk/src/share/classes/sun/tools/jinfo/JInfo.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/tools/jinfo/JInfo.java	Fri Dec 02 17:37:30 2011 +0000
@@ -98,7 +98,7 @@
     }
 
     // loads the given class using the system class loader
-    private static Class loadClass(String name) {
+    private static Class<?> loadClass(String name) {
         //
         // We specify the system clas loader so as to cater for development
         // environments where this class is on the boot class path but sa-jdi.jar
@@ -178,7 +178,7 @@
     // print usage message
     private static void usage() {
 
-        Class c = loadClass("sun.jvm.hotspot.tools.JInfo");
+        Class<?> c = loadClass("sun.jvm.hotspot.tools.JInfo");
         boolean usageSA = (c != null);
 
         System.out.println("Usage:");
--- a/jdk/src/share/classes/sun/tools/jmap/JMap.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/tools/jmap/JMap.java	Fri Dec 02 17:37:30 2011 +0000
@@ -198,7 +198,7 @@
     }
 
     // loads the given class using the system class loader
-    private static Class loadClass(String name) {
+    private static Class<?> loadClass(String name) {
         //
         // We specify the system clas loader so as to cater for development
         // environments where this class is on the boot class path but sa-jdi.jar
@@ -336,7 +336,7 @@
 
     // returns true if SA is available
     private static boolean haveSA() {
-        Class c = loadClass("sun.jvm.hotspot.tools.HeapSummary");
+        Class<?> c = loadClass("sun.jvm.hotspot.tools.HeapSummary");
         return (c != null);
     }
 
--- a/jdk/src/share/classes/sun/tools/jps/Jps.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/tools/jps/Jps.java	Fri Dec 02 17:37:30 2011 +0000
@@ -59,13 +59,13 @@
                     MonitoredHost.getMonitoredHost(hostId);
 
             // get the set active JVMs on the specified host.
-            Set jvms = monitoredHost.activeVms();
+            Set<Integer> jvms = monitoredHost.activeVms();
 
-            for (Iterator j = jvms.iterator(); j.hasNext(); /* empty */ ) {
+            for (Integer jvm: jvms) {
                 StringBuilder output = new StringBuilder();
                 Throwable lastError = null;
 
-                int lvmid = ((Integer)j.next()).intValue();
+                int lvmid = jvm;
 
                 output.append(String.valueOf(lvmid));
 
--- a/jdk/src/share/classes/sun/tools/jstack/JStack.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/tools/jstack/JStack.java	Fri Dec 02 17:37:30 2011 +0000
@@ -137,7 +137,7 @@
     }
 
     // Returns sun.jvm.hotspot.tools.JStack if available, otherwise null.
-    private static Class loadSAClass() {
+    private static Class<?> loadSAClass() {
         //
         // Attempt to load JStack class - we specify the system class
         // loader so as to cater for development environments where
--- a/jdk/src/share/classes/sun/tools/serialver/SerialVer.java	Fri Dec 02 14:17:08 2011 +0000
+++ b/jdk/src/share/classes/sun/tools/serialver/SerialVer.java	Fri Dec 02 17:37:30 2011 +0000
@@ -98,6 +98,7 @@
         classname_t.requestFocus();
     }
 
+    @SuppressWarnings("deprecation")
     public boolean action(Event ev, Object obj) {
         if (ev.target == classname_t) {
             show((String)ev.arg);
@@ -110,6 +111,7 @@
     }
 
 
+    @SuppressWarnings("deprecation")
     public boolean handleEvent(Event ev) {
         boolean rc = super.handleEvent(ev);
         return rc;
@@ -206,7 +208,7 @@
     }
 
     static String resolveClass(String classname) throws ClassNotFoundException {
-        Class cl = Class.forName(classname, false, loader);
+        Class<?> cl = Class.forName(classname, false, loader);
         ObjectStreamClass desc = ObjectStreamClass.lookup(cl);
         if (desc != null) {
             return "    static final long serialVersionUID = " +
@@ -216,6 +218,10 @@
         }
     }
 
+    @SuppressWarnings("deprecation")
+    private static void showWindow(Window w) {
+        w.show();
+    }
 
     public static void main(String[] args) {
         boolean show = false;
@@ -316,7 +322,7 @@
 
             f.add("Center", sv);
             f.pack();
-            f.show();
+            showWindow(f);
         }
     }
 
@@ -362,6 +368,7 @@
     /*
      * Handle a window destroy event by exiting.
      */
+    @SuppressWarnings("deprecation")
     public boolean handleEvent(Event e) {
         if (e.id == Event.WINDOW_DESTROY) {
             exit(0);
@@ -371,6 +378,7 @@
     /*
      * Handle an Exit event by exiting.
      */
+    @SuppressWarnings("deprecation")
     public boolean action(Event ev, Object obj) {
         if (ev.target == exit_i) {
             exit(0);
@@ -455,11 +463,7 @@
         }
         try {
             String message = messageRB.getString(key);
-            String[] args = new String[3];
-            args[0] = a1;
-            args[1] = a2;
-            args[2] = a3;
-            return MessageFormat.format(message, args);
+            return MessageFormat.format(message, a1, a2, a3);
         } catch (MissingResourceException e) {
             throw new Error("Fatal: Resource for serialver is broken. There is no " + key + " key in resource.");
         }