RFR: 8039173 Propagate errors from Diagnostic Commands as exceptions in the attach framework
Staffan Larsen
staffan.larsen at oracle.com
Fri Apr 4 11:47:03 UTC 2014
Thanks for finding these bugs, Ivan!
I have updated the webrev at: http://cr.openjdk.java.net/~sla/8039173/webrev.01/, and I have also included the diff below.
The updated webrev also has some changes in the javadoc for VirtualMachine to clarify that some methods can now throw AttachOperationFailedException.
Thanks,
/Staffan
diff --git a/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java b/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java
--- a/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java
+++ b/src/share/classes/sun/tools/attach/HotSpotVirtualMachine.java
@@ -266,18 +266,21 @@
*/
String getErrorMessage(InputStream sis, int maxlen) throws IOException {
byte b[] = new byte[maxlen];
- int n, off = 0, len = b.length;
+ int n, off = 0, len = maxlen;
do {
n = sis.read(b, off, len);
+ if (n == -1) {
+ break;
+ }
off += n;
len -= n;
- } while (n >= 0 && off < b.length);
+ } while (off < maxlen);
String message = null;
if (off > 0) {
message = new String(b, 0, off, "UTF-8");
}
- if (off == b.length && message != null) {
+ if (off > b.length && message != null) {
message += " ...";
}
return message;
On 4 apr 2014, at 11:18, Ivan Gerasimov <ivan.gerasimov at oracle.com> wrote:
> Hi Staffan!
>
> I think there is a couple of minor bugs in getErrorMessage(InputStream sis, int maxlen).
>
> 1) If maxlen is exactly the size of the message to read, the function will add an ellipsis, even though the message isn't truncated,
> 2) If maxlen is greater than needed, then sis.read(b, off, len) at the line #271 will eventually return -1, and it will cause the message to lose its last character.
>
> Sincerely yours,
> Ivan
>
More information about the serviceability-dev
mailing list