--- old/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java 2017-11-03 20:54:56.771130491 +0900 +++ new/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java 2017-11-03 20:54:56.524129681 +0900 @@ -39,6 +39,8 @@ import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Properties; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; /* @@ -86,18 +88,26 @@ private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { - InputStream in = execute("load", - agentLibrary, - isAbsolute ? "true" : "false", - options); - try { - int result = readInt(in); - if (result != 0) { - throw new AgentInitializationException("Agent_OnAttach failed", result); + try (BufferedReader reader = new BufferedReader( + new InputStreamReader( + execute("load", agentLibrary, + Boolean.toString(isAbsolute), options)))) { + String result = reader.readLine(); + if (result == null) { + throw new AgentLoadException("Target VM did not respond"); + } else { + Matcher matcher = Pattern.compile("^return code: (\\d+)$") + .matcher(result); + if (matcher.matches()) { + int retCode = Integer.parseInt(matcher.group(1)); + if (retCode != 0) { + throw new AgentInitializationException( + "Agent_OnAttach failed", retCode); + } + } else { + throw new AgentLoadException(result); + } } - } finally { - in.close(); - } }