How to Crash the JVM in Three Lines of Code

This is a confirmed JDK bug. Just three lines of code to crash the Windows JVM.

public static void main (String[] args) throws Exception {
    System.setProperty("java.awt.headless", "true");
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    JComboBox<Object> combo = new JComboBox<>();
}

I came across this while working on a large automated test suite. As you can see, having application code hardcoding a look & feel when test framework has already set ‘headless’ mode leads to trouble. 🙂

Bug JDK-8183392

Oracle say this should be fixed in Java 9.

Leave a Reply

Your email address will not be published. Required fields are marked *