You can enable/disable assert
on the ClassLoader
.
But how can you determine if they are already enabled?
(I want to take some code paths that perform expensive checks only if the JVM is invoked with assertions enabled.)
public static boolean areAssertsEnabled() {
boolean assertsEnabled = false;
assert assertsEnabled = true; // Intentional side effect!!!
return assertsEnabled;
}
boolean assertEnabled = false;
try {
assert false;
} catch (AssertionError e) {
assertEnabled = true;
}
ManagementFactory.getRuntimeMXBean().getInputArguments().contains("-ea");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With