New candidate JEP: 506: Scoped Values

Adam Gent dev at adamgent.com
Tue Apr 15 18:05:44 UTC 2025


On Tue, Apr 15, 2025, at 1:58 PM, Alan Bateman wrote:
> 
> 
> On 15/04/2025 17:17, Adam Gent wrote:
>> 
>> For those that do not want to go to reddit the gist is I think if we do not allow null in a Scoped Value it makes the API less bloated and easier to use with pattern matching. 
> Just to add to Andrew's comments.  If you think of a scoped value an implicit parameter then it would be surprising to allow an explicit parameter be null but not an implicit parameter. As it happens, the first usage of ScopedValue API was Subject which does bind to a null value. In any case, as Andrew said, once we have null-restricted types then a nullness marker can be used. The orElse(V) method doesn't allow null so it might become orElse(V!). There may be an argument to add an orNull() for cases where code wants to gracefully handle the case that it is called without a binding and not use a sentinel, that hasn't been ruled out.
> 
> -Alan

And also to play devils advocate against myself the existing ThreadLocal API allows `null` binding so this may make it easier to understand and port given ScopedValue will allow it as well. For Valhalla and newer pattern matching I'm sort of in the dark so I trust this will work out and assume those newer features will probably mitigate my safety concerns.

-Adam


More information about the loom-dev mailing list