Record constructor using Objects.requireNonNull

Remi Forax forax at univ-mlv.fr
Fri Jan 1 14:52:31 UTC 2021


Yes,
definitively a bug !

Rémi

----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Christian Stein" <sormuras at gmail.com>, "amber-dev" <amber-dev at openjdk.java.net>
> Envoyé: Jeudi 31 Décembre 2020 23:09:14
> Objet: Re: Record constructor using Objects.requireNonNull

> 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