That looks like a compiler bug (probably a hangover from the previous preview where total patterns could match null). The current spec has no rules concerning dominance of null.
http://cr.openjdk.java.net/~gbierman/jep427%2b405/jep427+405-20220601/specs/patterns-switch-record-patterns-jls.html<http://cr.openjdk.java.net/~gbierman/jep427+405/jep427+405-20220601/specs/patterns-switch-record-patterns-jls.html#jls-15.28> Thanks! Gavin On 20 Jul 2022, at 09:54, Tagir Valeev <[email protected]<mailto:[email protected]>> wrote: Hello! Playing with Java 19, we stumbled upon this sample: public class Main { public static void main(String[] args) { Integer x = null; switch (x) { case Integer i -> System.out.println(i); case null -> System.out.println("null is supplied!"); } } } Latest javac 19-ea says that this code is not compilable, as Integer i is dominated by null. However, if we remove `case null`, then `case Integer i` doesn't match the `null` (NPE is thrown). I find it strange that `case Integer i` matches null when `case null` is supplied and I'm forced to use `case null` before `case Integer i`. Is it expected behavior? With best regards, Tagir Valeev.
