RFR: 8335896: Source launcher should set TCCL [v2]
Alan Bateman
alanb at openjdk.org
Tue Jul 16 08:52:56 UTC 2024
On Tue, 16 Jul 2024 08:43:01 GMT, Christian Stein <cstein at openjdk.org> wrote:
>> The try-catch cares for `ClassNotFoundException` instances thrown by `Class.forName()` - which doesn't initialize the main class. But swapping the lines to read:
>>
>> Thread.currentThread().setContextClassLoader(loader);
>> firstClass = Class.forName(firstClassName, false, loader);
>>
>> should better ensure that the TCCL is set before the initializer for the main class runs.
>
> I found a better way to move the `TCCL`-related above the try-catch block.
Good, I was puzzled why newClassLoaderFor was declared to throw CNFE. Related question is do you know why it uses Class.forName without running the class initializer? I guess I expected it would load loader.loadClass(firstClassName) and let the initializer run (it's going to run a bit later anyway). Main thing is that the initializer may do anything and the TCCL needs to be set before that executes (which is what you have now).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20097#discussion_r1679008980
More information about the compiler-dev
mailing list