8177721: Improve diagnostics in sun.management.Agent#startAgent()
authorshshahma
Thu, 27 Apr 2017 00:08:24 -0700
changeset 45009 c39425655469
parent 45006 1c15ce5f636c
child 45010 f5764d8f5502
8177721: Improve diagnostics in sun.management.Agent#startAgent() Reviewed-by: dfuchs, dholmes, poonam
jdk/src/jdk.management.agent/share/classes/jdk/internal/agent/Agent.java
--- a/jdk/src/jdk.management.agent/share/classes/jdk/internal/agent/Agent.java	Thu May 04 20:24:12 2017 +0800
+++ b/jdk/src/jdk.management.agent/share/classes/jdk/internal/agent/Agent.java	Thu Apr 27 00:08:24 2017 -0700
@@ -393,7 +393,7 @@
         } catch (JdpException e) {
             error(e);
         } catch (AgentConfigurationError err) {
-            error(err.getError(), err.getParams());
+            error(err);
         }
     }
 
@@ -454,7 +454,7 @@
             }
 
         } catch (AgentConfigurationError e) {
-            error(e.getError(), e.getParams());
+            error(e);
         } catch (Exception e) {
             error(e);
         }
@@ -665,18 +665,6 @@
         throw new RuntimeException(keyText);
     }
 
-    public static void error(String key, String[] params) {
-        if (params == null || params.length == 0) {
-            error(key);
-        } else {
-            StringBuilder message = new StringBuilder(params[0]);
-            for (int i = 1; i < params.length; i++) {
-                message.append(' ').append(params[i]);
-            }
-            error(key, message.toString());
-        }
-    }
-
     public static void error(String key, String message) {
         String keyText = getText(key);
         System.err.print(getText("agent.err.error") + ": " + keyText);
@@ -690,6 +678,23 @@
         throw new RuntimeException(e);
     }
 
+    public static void error(AgentConfigurationError e) {
+        String keyText = getText(e.getError());
+        String[] params = e.getParams();
+
+        System.err.print(getText("agent.err.error") + ": " + keyText);
+
+        if (params != null && params.length != 0) {
+           StringBuffer message = new StringBuffer(params[0]);
+           for (int i = 1; i < params.length; i++) {
+               message.append(" " + params[i]);
+           }
+           System.err.println(": " + message);
+        }
+        e.printStackTrace();
+        throw new RuntimeException(e);
+    }
+
     public static void warning(String key, String message) {
         System.err.print(getText("agent.err.warning") + ": " + getText(key));
         System.err.println(": " + message);