src/jdk.attach/aix/classes/sun/tools/attach/VirtualMachineImpl.java
Print this page
rev 11622 : 8071687: AIX port of "8039173: Propagate errors from Diagnostic Commands as exceptions in the attach framework"
@@ -1,8 +1,8 @@
/*
- * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved.
- * Copyright 2013 SAP AG. All rights reserved.
+ * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2015 SAP AG. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,13 +23,15 @@
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package sun.tools.attach;
+import com.sun.tools.attach.AttachOperationFailedException;
import com.sun.tools.attach.AgentLoadException;
import com.sun.tools.attach.AttachNotSupportedException;
import com.sun.tools.attach.spi.AttachProvider;
+
import java.io.InputStream;
import java.io.IOException;
import java.io.File;
// Based on linux/classes/sun/tools/attach/VirtualMachineImpl.java.
@@ -187,10 +189,12 @@
throw x;
}
}
if (completionStatus != 0) {
+ // read from the stream and use that as the error message
+ String message = readErrorMessage(sis);
sis.close();
// In the event of a protocol mismatch then the target VM
// returns a known error so that we can throw a reasonable
// error.
@@ -201,11 +205,15 @@
// Special-case the "load" command so that the right exception is
// thrown.
if (cmd.equals("load")) {
throw new AgentLoadException("Failed to load agent library");
} else {
- throw new IOException("Command failed in target VM");
+ if (message == null) {
+ throw new AttachOperationFailedException("Command failed in target VM");
+ } else {
+ throw new AttachOperationFailedException(message);
+ }
}
}
// Return the input stream so that the command output can be read
return sis;