Close

Using JVM Option -XX:+ShowMessageBoxOnError

[Last Updated: May 20, 2018]

Java Tools & Commands Java 

When JVM option -XX:+ShowMessageBoxOnError is set and a fatal error is encountered, the HotSpot VM will display information about the fatal error and prompt the user to specify whether the native debugger is to be launched.


How to test?

Java class:

import sun.misc.Unsafe;
import java.lang.reflect.Field;

public class Test {
public static void main(String... args) throws Exception {

Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
Unsafe unsafe = (sun.misc.Unsafe) field.get(null);
unsafe.getByte(0);
}
}


Compile above Java class. We will get warnings, we are just ignoring them:

D:\test>javac Test.java
Test.java:1: warning: Unsafe is internal proprietary API and may be removed in a future release
import sun.misc.Unsafe;
^
Test.java:8: warning: Unsafe is internal proprietary API and may be removed in a future release
Field field = Unsafe.class.getDeclaredField("theUnsafe");
^
Test.java:10: warning: Unsafe is internal proprietary API and may be removed in a future release
Unsafe unsafe = (Unsafe) field.get(null);
^
Test.java:10: warning: Unsafe is internal proprietary API and may be removed in a future release
Unsafe unsafe = (Unsafe) field.get(null);
^

Now run the compiled class without -XX:+ShowMessageBoxOnError Option:


D:\test>java Test
#
# A fatal error has been detected by the Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000057d44b3f, pid=2080, tid=14056
#
# JRE version: Java(TM) SE Runtime Environment (8.0_71-b15) (build 1.8.0_71-b15)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.71-b15 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# V [jvm.dll+0x1e4b3f]
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# D:\test\hs_err_pid2080.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#

Now that we have crashed JVM successfully, let's run with -XX:+ShowMessageBoxOnError Option

java -XX:+ShowMessageBoxOnError Test

A message dialog will be shown this time:


If you have the native debugger set up then click yes, otherwise no.

I'm using windows and need Visual Studio to debug natively.

See Also