/* * @test * @summary moving predicate out of loops may cause array accesses to bypass null check and caused crash * @run main/othervm -Xbatch -XX:-TieredCompilation -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+StressGCM -XX:CompileCommand=compileonly,TestBypassNullCheck::getController TestBypassNullCheck */ public class TestBypassNullCheck { Config initConfig; public TestBypassNullCheck() { initConfig = new Config(1234, "test"); } public TestBypassNullCheck getController() { String customGroupName = initConfig.userName == null ? "" : initConfig.userName; customGroupName = customGroupName + ":" + initConfig.dataId; State.setCustomName(customGroupName); return this; } public static void main(String [] args) { System.out.println("test"+":"+args.length+State.getCustomName()); TestBypassNullCheck t = new TestBypassNullCheck(); for (int i=0;i<10000;i++) { t.getController(); } t.initConfig = new Config(1234, null); t.getController(); } } class Config { String dataId; String userName; public Config(long id, String name) { dataId = ""+id; userName = name; } } class State { static String customerName="test"; public static void setCustomName(String name) { customerName = name; } public static String getCustomName() { return customerName; } }