Skip to content

Instantly share code, notes, and snippets.

@corneil
Created September 3, 2025 11:38
Show Gist options
  • Select an option

  • Save corneil/dce44233716f7dc61769509dbb2e71f7 to your computer and use it in GitHub Desktop.

Select an option

Save corneil/dce44233716f7dc61769509dbb2e71f7 to your computer and use it in GitHub Desktop.
Utility for determining if JVM is running assertions enabled.
public class AssertionUtils {
public static boolean assertionsEnabled = false;
static {
// When this class is loaded the static block will execute and it the application is running with -ea the value of assertionsEnabled will be set to true.
//noinspection AssertWithSideEffects
assert (assertionsEnabled = true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment