Current thinking about the future nullability of java.time.Duration
Roger Riggs
roger.riggs at oracle.com
Thu Jan 2 14:12:32 UTC 2025
Hi,
In addition, changing from null allowed to null-restricted in APIs would
be an incompatible change.
So existing uses would not be changed.
It would be advisable (as always) in new APIs to be very specific about
the meaning of null; throwing or allowed.
As currently specified, there is no clean Duration value that could be
used as a sentinel (alternative to null) except in a some application
specific use.
Happy New Year, Roger
On 12/29/24 2:48 PM, Glavo wrote:
> Hi Jean-Noël,
>
> From what I understand, the null-restricted types are use-site
> specified, which means that `Duration` is not null-restricted, but
> `Duration!` is null-restricted, even though it is a value class.
>
> It is also worth noting that null-restricted types are not a
> requirement for flattening value objects.
> For a variable of a nullable value type, Valhalla may use a "null
> channel" to distinguish between null and non-null values.
> The null channel could be a boolean variable or something else, you
> can read this article[1] to learn more about it.
>
> Glavo
>
> [1]: https://cr.openjdk.org/~jrose/values/flattened-values.html
>
> On Mon, Dec 30, 2024 at 12:49 AM Jean-Noël Rouvignac
> <jean-noel.rouvignac at pingidentity.com> wrote:
>
> Hello,
>
> I have a use case for configuration objects where I would like to
> use java.time.Duration to represent time intervals, timeouts,
> delays, etc. for example.
>
> In these configuration objects, sometimes users may not provide a
> value, and the configuration framework does not have a default
> value for it either. This is to be interpreted as "disable the
> feature" or "let the library decide". For this specific case, I
> was considering returning `null` to mean "disable the feature" or
> "let the library decide".
>
> java.time.Duration being marked as a value based class, I wanted
> to confirm that using `null` will not force significant rework in
> the future? i.e. java.time.Duration will not opt-in to become a
> null-restricted value class type (https://openjdk.org/jeps/8316779).
>
> Thanks a lot, and thanks for the huge work on Valhalla. Good luck
> for bringing it into mainline Java !
>
> Jean-Noël
>
> /CONFIDENTIALITY NOTICE: This email may contain confidential and
> privileged material for the sole use of the intended recipient(s).
> Any review, use, distribution or disclosure by others is strictly
> prohibited. If you have received this communication in error,
> please notify the sender immediately by e-mail and delete the
> message and any file attachments from your computer. Thank you./
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20250102/bb307b6b/attachment.htm>
More information about the valhalla-dev
mailing list