import org.jetbrains.annotations.Nullable; class Test { @Nullable volatile String x; public void foo() { if (x != null) { System.out.println(x.substring(1)); } } }