Skip to content

Instantly share code, notes, and snippets.

@baybatu
Created October 12, 2017 05:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baybatu/795b28966a8fe396c074be78e63f1032 to your computer and use it in GitHub Desktop.
Save baybatu/795b28966a8fe396c074be78e63f1032 to your computer and use it in GitHub Desktop.
getting info on whether JVM started in debug mode.
/**
*
* -----------------------------------------------------------------------------------
* From : org.junit.rules.DisableOnDebug#isDebugging(java.util.List<java.lang.String>)
* -----------------------------------------------------------------------------------
*
* Parses arguments passed to the runtime environment for debug flags
* <p>
* Options specified in:
* <ul>
* <li>
* <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/jpda/conninv.html#Invocation"
* >javase-6</a></li>
* <li><a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jpda/conninv.html#Invocation"
* >javase-7</a></li>
* <li><a href="http://docs.oracle.com/javase/8/docs/technotes/guides/jpda/conninv.html#Invocation"
* >javase-8</a></li>
*
*
* @param arguments
* the arguments passed to the runtime environment, usually this
* will be {@link RuntimeMXBean#getInputArguments()}
* @return true if the current JVM was started in debug mode, false
* otherwise.
*/
private static boolean isDebugging(List<String> arguments) {
for (final String argument : arguments) {
if ("-Xdebug".equals(argument)) {
return true;
} else if (argument.startsWith("-agentlib:jdwp")) {
return true;
}
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment