changeset 8700:a9717ab00796

7117357: Warnings in sun.instrument, tools and other sun.* classes Reviewed-by: lancea, chegar
author alanb
date Fri, 07 Jul 2017 15:59:03 +0100
parents 15ba571f7278
children 848ccfd27743
files src/share/classes/sun/instrument/InstrumentationImpl.java src/share/classes/sun/instrument/TransformerManager.java src/share/classes/sun/management/counter/perf/PerfInstrumentation.java src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java src/share/classes/sun/net/RegisteredDomain.java src/share/classes/sun/net/www/protocol/jar/Handler.java src/share/classes/sun/tools/attach/HotSpotAttachProvider.java src/share/classes/sun/tools/jinfo/JInfo.java src/share/classes/sun/tools/jmap/JMap.java src/share/classes/sun/tools/jps/Jps.java src/share/classes/sun/tools/jstack/JStack.java src/share/classes/sun/tools/serialver/SerialVer.java
diffstat 12 files changed, 62 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/instrument/InstrumentationImpl.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/instrument/InstrumentationImpl.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/instrument/TransformerManager.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/instrument/TransformerManager.java	Fri Jul 07 15:59:03 2017 +0100
@@ -169,7 +169,7 @@
     public byte[]
     transform(  ClassLoader         loader,
                 String              classname,
-                Class               classBeingRedefined,
+                Class<?>            classBeingRedefined,
                 ProtectionDomain    protectionDomain,
                 byte[]              classfileBuffer) {
         boolean someoneTouchedTheBytecode = false;
--- a/src/share/classes/sun/management/counter/perf/PerfInstrumentation.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/management/counter/perf/PerfInstrumentation.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java	Fri Jul 07 15:59:03 2017 +0100
@@ -237,16 +237,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(
@@ -709,7 +707,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/src/share/classes/sun/net/RegisteredDomain.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/net/RegisteredDomain.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/net/www/protocol/jar/Handler.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/net/www/protocol/jar/Handler.java	Fri Jul 07 15:59:03 2017 +0100
@@ -123,6 +123,7 @@
 
 
     @Override
+    @SuppressWarnings("deprecation")
     protected void parseURL(URL url, String spec,
                             int start, int limit) {
         String file = null;
--- a/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/tools/attach/HotSpotAttachProvider.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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();          // 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/src/share/classes/sun/tools/jinfo/JInfo.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/tools/jinfo/JInfo.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/tools/jmap/JMap.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/tools/jmap/JMap.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/tools/jps/Jps.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/tools/jps/Jps.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/tools/jstack/JStack.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/tools/jstack/JStack.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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/src/share/classes/sun/tools/serialver/SerialVer.java	Wed May 03 03:39:53 2017 +0100
+++ b/src/share/classes/sun/tools/serialver/SerialVer.java	Fri Jul 07 15:59:03 2017 +0100
@@ -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.");
         }