RFR: 8357915: SecureRandom nextLong memory usage
Chen Liang
liach at openjdk.org
Mon Jun 30 15:14:39 UTC 2025
On Mon, 30 Jun 2025 13:18:58 GMT, Sean Mullan <mullan at openjdk.org> wrote:
>> SecureRandom uses straightforward implementations inherited from Random but in the process does double the memory allocations necessary.
>> The delegation to SecureRandom.engineNextBytes does not provide `int` or `long` values, the caller must allocate a byte array and assemble the value itself.
>> So added an implementation in SecureRandom that call nextBytes(8 bytes) and then convert that to a long.
>
> src/java.base/share/classes/java/security/SecureRandom.java line 841:
>
>> 839: }
>> 840:
>> 841: @Override
>
> This method will appear in the javadoc for `SecureRandom` now, so I think you need to add the `inheritDoc` tag to incorporate the superclass` javadoc.
This won't appear in the list of methods declared by `SecureRandom`. An analogy is [`ConcurrentHashMap::forEach(BiConsumer)`](https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/util/concurrent/ConcurrentHashMap.html#methods-inherited-from-class-java.util.concurrent.ConcurrentMap): this method is [overridden in `ConcurrentHashMap`](https://github.com/openjdk/jdk/blob/jdk24/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java#L1613) but is described by Javadoc as "Methods declared in interface java.util.concurrent.ConcurrentMap".
Since this method won't appear, we don't need an `@inheritDoc` tag.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/26005#discussion_r2175319564
More information about the security-dev
mailing list