--- /dev/null 2020-09-25 10:21:33.958375795 +0800 +++ new/test/compiler/8069191/TestBypassNullCheck.java 2021-04-28 19:35:17.024465269 +0800 @@ -0,0 +1,42 @@ +/* + * @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; } +}