NPE wrapped in a MatchException when matching a record pattern

Remi Forax forax at univ-mlv.fr
Wed Nov 16 11:01:26 UTC 2022


Hi all,
Jan and Brian already knows that bug but for the record:

This snippet of code should print "B" but currently throw a NPE wrapped into a MatchingException.


  record Box<E>(E element) {}

  public static void main(String[] args) {
    Box<Box<String>> bbs = new Box<>(null);
    switch (bbs) {
      case Box<Box<String>>(Box<String>(String s)) -> System.out.println("A");
      case Box<Box<String>>(Box<?> b) -> System.out.println("B");
      default -> System.out.println("C");
    }
  }


Exception in thread "main" java.lang.MatchException: java.lang.NullPointerException: Cannot invoke "Box.element()" because "arg0" is null
	at Test.$proxy$element(Test.java:6)
	at Test.main(Test.java:6)
Caused by: java.lang.NullPointerException: Cannot invoke "Box.element()" because "arg0" is null
	... 2 more

regards,
Rémi


More information about the amber-dev mailing list