--- old/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java 2017-11-20 16:43:16.192929099 +0900 +++ new/src/jdk.attach/share/classes/sun/tools/attach/HotSpotVirtualMachine.java 2017-11-20 16:43:15.956928553 +0900 @@ -86,18 +86,24 @@ private void loadAgentLibrary(String agentLibrary, boolean isAbsolute, String options) throws AgentLoadException, AgentInitializationException, IOException { + String msgPrefix = "return code: "; InputStream in = execute("load", agentLibrary, isAbsolute ? "true" : "false", options); - try { - int result = readInt(in); - if (result != 0) { - throw new AgentInitializationException("Agent_OnAttach failed", result); + BufferedReader reader = new BufferedReader(new InputStreamReader(in)); + try (reader) { + String result = reader.readLine(); + if (result == null) { + throw new AgentLoadException("Target VM did not respond"); + } else if (result.startsWith(msgPrefix)) { + int retCode = Integer.parseInt(result.substring(msgPrefix.length())); + if (retCode != 0) { + throw new AgentInitializationException("Agent_OnAttach failed", retCode); + } + } else { + throw new AgentLoadException(result); } - } finally { - in.close(); - } }