Permalink
Browse files

added extra fallback for obtaining pid on Windows -- fixes BTEMAN-255

n.b many thanks very much to antoine vianey (antoine dot vianey at
gmail dot com) for contributing code for this fix
  • Loading branch information...
1 parent 62055c0 commit e5efcb1295f0d2d7c34e0a0cd057ecadf0120b4f @adinn adinn committed Dec 5, 2013
Showing with 21 additions and 0 deletions.
  1. +21 −0 contrib/bmunit/src/org/jboss/byteman/contrib/bmunit/BMUnit.java
View
21 contrib/bmunit/src/org/jboss/byteman/contrib/bmunit/BMUnit.java
@@ -7,6 +7,7 @@
import org.jboss.byteman.agent.submit.Submit;
import java.io.*;
+import java.lang.management.ManagementFactory;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
@@ -286,6 +287,26 @@ private static synchronized void loadAgent() throws Exception
break;
}
}
+ // last ditch effort to obtain pid on Windows where the availableVMs list may be empty
+ if (id == null) {
+ String processName = ManagementFactory.getRuntimeMXBean().getName();
+ if (processName != null && processName.contains("@")) {
+ id = processName.substring(0, processName.indexOf("@"));
+ // check we actually have an integer
+ try {
+ Integer.parseInt(id);
+ // well, it's a number so now check it identifies the current VM
+ String value = Install.getSystemProperty(id, prop);
+ if (!unique.equals(value)) {
+ // nope, not the right process
+ id = null;
+ }
+ } catch (NumberFormatException e) {
+ // nope, not a number
+ id = null;
+ }
+ }
+ }
// make sure we found a process
if (id == null) {
throw new Exception("BMUnit : Unable to identify test JVM process during agent load");

0 comments on commit e5efcb1

Please sign in to comment.