On Tue, 20 May 2025 12:00:06 GMT, kieran-farrell <[email protected]> wrote:
>> src/java.base/share/classes/java/util/UUID.java line 195:
>>
>>> 193: *
>>> 194: * @return A {@code UUID} generated from the current system time
>>> 195: */
>>
>> Seems like there should be a reference to the RFC somewhere here using the
>> @spec javadoc tag.
>>
>> And also in the class javadoc.
>
> spec updated in class javadoc to RFC 9562 which obsolete RFC 4122, @spec tag
> also added above the method.
I'd say "create" instead of "retrieve" in the first line comment. (Though that
word is used in the other static factories).
The "sub-millisecond precision" can't be relied upon. Its the precision that
gives the impression that it can be added to the millisecond value and get an
exact time. But the nano-second value is read from a different clock and the
bits being used from it may wrap-around in the time between the reads of the
clocks.
The second description ("derived from") is makes fewer promises than the
first-line comment.
An application should not use them for any purpose other than random. And for
that the buffer already contains random bytes.
An alternative is to capture the MS time and the nano-time on first use to
compute an offset and then use only the nano-time plus/minus the offset to
create the version 7 UUIDs.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25303#discussion_r2110340184