--- a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java Thu Oct 17 20:27:44 2019 +0100
+++ b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java Thu Oct 17 20:53:35 2019 +0100
@@ -60,8 +60,11 @@
int pid;
try {
pid = Integer.parseInt(vmid);
+ if (pid < 1) {
+ throw new NumberFormatException();
+ }
} catch (NumberFormatException x) {
- throw new AttachNotSupportedException("Invalid process identifier");
+ throw new AttachNotSupportedException("Invalid process identifier: " + vmid);
}
// Try to resolve to the "inner most" pid namespace
@@ -233,7 +236,7 @@
* InputStream for the socket connection to get target VM
*/
private class SocketInputStream extends InputStream {
- int s;
+ int s = -1;
public SocketInputStream(int s) {
this.s = s;
@@ -260,8 +263,12 @@
return VirtualMachineImpl.read(s, bs, off, len);
}
- public void close() throws IOException {
- VirtualMachineImpl.close(s);
+ public synchronized void close() throws IOException {
+ if (s != -1) {
+ int toClose = s;
+ s = -1;
+ VirtualMachineImpl.close(toClose);
+ }
}
}