On Sun, 18 Jan 2026 09:51:39 GMT, Eirik Bjørsnøs <[email protected]> wrote:
>> src/java.base/share/classes/jdk/internal/loader/URLClassPath.java line 485:
>>
>>> 483: // Lazily create list
>>> 484: if (loaderPath == null) {
>>> 485: loaderPath = new ArrayList<>();
>>
>> This will always be used if we are using `JarLoader`, which seems to be used
>> in the majority of cases. I recommend initializing this dfs variable
>> unconditionally.
>
>> This will always be used if we are using `JarLoader`, which seems to be used
>> in the majority of cases.
>
> Not exactly, `push` is only called when the JAR uses the 'Class-Path:'
> attribute. I don't have data to support this, but from personal experience I
> don't see this being used too often.
>
>> I recommend initializing this dfs variable unconditionally.
>
> GIven the above, do you still think it's worth initializing this eagerly? It
> would allow us to make the field final and avoid a null check.
>
> EDIT: Decided to initialize eagerly and make the field final, see below.
`ArrayList` initializes its backing array lazily when using that constructor,
so I think there isn't much reason to do a "double lazy" initialization.
(It *might* make sense to initialize the list with a different size (e.g.
`urls.length`), but I guess we'd need some real-world data on this. And I don't
think that's worth the effort.)
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29288#discussion_r2702293940