src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java
branchdatagramsocketimpl-branch
changeset 58678 9cf78a70fa4f
parent 54065 f984aca565c1
child 58679 9c3209ff7550
--- a/src/jdk.attach/solaris/classes/sun/tools/attach/VirtualMachineImpl.java	Thu Oct 17 20:27:44 2019 +0100
+++ b/src/jdk.attach/solaris/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);
         }
 
         // Opens the door file to the target VM. If the file is not
@@ -204,8 +207,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);
+            }
         }
     }