RFR: JDK-8281000 ClassLoader::registerAsParallelCapable throws NPE if caller is null [v2]

Mandy Chung mchung at openjdk.java.net
Tue Feb 15 23:23:11 UTC 2022


On Tue, 15 Feb 2022 23:05:30 GMT, Mandy Chung <mchung at openjdk.org> wrote:

>> Tim Prinzing has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Changes from feedback.
>>   
>>   - Copyright dates fixed
>>   - IllegalCallerException thrown for no caller frame, and associated
>>   javadoc changes
>>   - test changed to look for IllegalCallerException thrown.
>
> src/java.base/share/classes/java/lang/ClassLoader.java line 1626:
> 
>> 1624:     protected static boolean registerAsParallelCapable() {
>> 1625:         final Class<?> caller = Reflection.getCallerClass();
>> 1626:         if (caller == null) {
> 
> Suggestion:
> 
>         if (caller == null || !ClassLoader.class.isAssignableFrom(caller)) {
>              throw new IllegalCallerException(caller + " not a subclass of ClassLoader");
>         }     
> 
> 
> What we suggested is to throw IllegalCallerException if the caller is not a class loader and that will include null caller case.

This also needs a test case for non-class loader caller.

I looked at the existing tests testing `registerAsParallelCapable` but I can't find a good one to add the new test case.   The closest one could be `test/jdk/java/lang/ClassLoader/IsParallelCapable.java`.   I'm okay to include a new test case in `IsParallelCapable.java` to verify `IllegalCallerException` if called by a non-class loader.

-------------

PR: https://git.openjdk.java.net/jdk/pull/7448


More information about the core-libs-dev mailing list