Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8333169

javac NullPointerException record.type

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 23
    • 22, 23
    • tools
    • None
    • b26

      Source: https://mail.openjdk.org/pipermail/compiler-dev/2024-May/026716.html

      Copied from the mailing list:

      Hi,
      I found a javac error, but the Java bug reporting page didn't allow me
      to submit the bug. Posting the reproducer here.
      Tried on Linux and Windows.

      jdk-22.0.1/bin/javac Main.java
      ...
      java.lang.NullPointerException: Cannot invoke
      "com.sun.tools.javac.code.Type.isErroneous()" because "record.type" is
      null
          at jdk.compiler/com.sun.tools.javac.comp.Flow.makePatternDescription(Flow.java:3471)
      ...


      class Main {

          record A() {};

          public static void main(String[] args) {
              A a1 = new A();
              A a2 = new A();

              ///
              String causesCompilationError = log(
                      switch(a1) {
                          case A() -> switch(a2) {
                              case A() -> "A";
                          };
                      }
              );
              ///

              String worksNonPattern = log(
                      switch(a1) {
                          case A _ -> switch(a2) {
                              case A _ -> "A";
                          };
                      }
              );

              String worksNonNested = log(
                      switch(a1) {
                          case A() -> "A";
                      }
              );
           }

          static <T> T log(T t) {
              System.out.println("LOG: " + t);
              return t;
          }
      }

            jlahoda Jan Lahoda
            cstein Christian Stein
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: