Record pattern and enhanced for

Robbe Pincket robbepincket at live.be
Mon Oct 24 17:45:56 UTC 2022


>> There is also a minor issue that looks like an overlook but refactoring an exhanced for from using a declaration to a record pattern is a little dangerous because if the iterable is null the semantics change, with the record pattern it throws a MatchException instead of a NPE.
>
> Yeah, it might make sense to special-case null here, though the
> MatchException has to stay in the general case of "looked exhaustive at
> compile time, but wasn't at run time."

I'm quite confused here. I don't see any mention of foreach throwing an
MatchException instead of NPE when the iterable is null.

I also don't understand the reasoning for making the foreach throw a
MatchException when one of the items is null instead of a simple NPE.

Regards
Robbe Pincket
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-spec-observers/attachments/20221024/9cd0201f/attachment.htm>


More information about the amber-spec-observers mailing list