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

Record compact constructor using Objects.requireNonNull

    Details

    • Subcomponent:
    • Resolved In Build:
      b05
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        Using all requireNonNull variants of java.util.Objects

          import static java.util.Objects.*;
          record Test(String v) {
            Test {
              requireNonNull(v);
              requireNonNull(v, "v must be provided");
              // requireNonNull(v, () -> "v must be provided");
              requireNonNullElse(v, "w");
              // requireNonNullElseGet(v, () -> "w");
            }
          }

        leads to this error message after uncommenting one or both of the supplier-taking lines:

          Test.java:2: error: invalid compact constructor in record <init>
            Test {
            ^
          (compact constructor must not have return statements)
          1 error

        Observed with javac 16-ea+27 and 17-ea+3.

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  attila Attila Szegedi
                  Reporter:
                  cstein Christian Stein
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  10 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: