Record constructor using Objects.requireNonNull
Brian Goetz
brian.goetz at oracle.com
Thu Dec 31 22:09:14 UTC 2020
Looks like a bug.
On 12/31/2020 1:22 PM, Christian Stein wrote:
> Hi,
>
> Sascha's finding [1] applied to 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
>
> I ran javac from 16-ea+27 and 17-ea+3.
>
> Shall I create an issue for this at https://bugs.openjdk.java.net or is
> this an expected behaviour?
>
> Cheers,
> Christian
>
> [1]: https://twitter.com/skohlmann/status/1344684426836500480
More information about the amber-dev
mailing list