<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
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.
<div class=""><br class="">
</div>
<div class=""><a href="http://cr.openjdk.java.net/~gbierman/jep427+405/jep427+405-20220601/specs/patterns-switch-record-patterns-jls.html#jls-15.28" class="">http://cr.openjdk.java.net/~gbierman/jep427%2b405/jep427+405-20220601/specs/patterns-switch-record-patterns-jls.html</a></div>
<div class=""><br class="">
</div>
<div class="">Thanks!</div>
<div class="">Gavin<br class="">
<div><br class="">
<blockquote type="cite" class="">
<div class="">On 20 Jul 2022, at 09:54, Tagir Valeev <<a href="mailto:amaembo@gmail.com" class="">amaembo@gmail.com</a>> wrote:</div>
<br class="Apple-interchange-newline">
<div class="">
<div class="">Hello!<br class="">
<br class="">
Playing with Java 19, we stumbled upon this sample:<br class="">
<br class="">
public class Main {<br class="">
 public static void main(String[] args) {<br class="">
   Integer x = null;<br class="">
   switch (x) {<br class="">
     case Integer i -> System.out.println(i);<br class="">
     case null -> System.out.println("null is supplied!");<br class="">
   }<br class="">
 }<br class="">
}<br class="">
<br class="">
Latest javac 19-ea says that this code is not compilable, as Integer i<br class="">
is dominated by null. However, if we remove `case null`, then `case<br class="">
Integer i` doesn't match the `null` (NPE is thrown). I find it strange<br class="">
that `case Integer i` matches null when `case null` is supplied and<br class="">
I'm forced to use `case null` before `case Integer i`. Is it expected<br class="">
behavior?<br class="">
<br class="">
With best regards,<br class="">
Tagir Valeev.<br class="">
</div>
</div>
</blockquote>
</div>
<br class="">
</div>
</body>
</html>