RFR: JDK-8281000 ClassLoader::registerAsParallelCapable throws NPE if caller is null
Brent Christian
bchristi at openjdk.java.net
Fri Feb 11 23:29:05 UTC 2022
On Fri, 11 Feb 2022 22:37:57 GMT, Mandy Chung <mchung at openjdk.org> wrote:
> Thanks for taking on these null caller issue.
>
> To give more context to this issue, the spec of `ClassLoader::isRegisteredAsParallelCapable` returns true if this class loader is registered as parallel capable, otherwise false. The current spec does not specify what if the caller class is not a class loader. The current implementation throws NPE if caller is null. I initially proposed to return false for simplicity. However, if the caller is not a subclass of `ClassLoader`, the current implementation throws `ClassCastException`. Both cases are invalid caller and they should be handled in the same way, either return false or throw an exception.
>
> Having a second thought, since this API expects to be called by a class loader, I think throwing `IllegalCallerException` to indicate this method is called by an illegal caller. This will need a CSR due to the spec change.
>
> What do you think?
Throwing IllegalCallerException sounds good to me.
As a static method, from a language standpoint, the call could appear almost anywhere. But its intended usage is pretty narrow. I think it's worth notifying the developer of a pretty obvious error.
Is this method mainly meant to be called from a classloader's static initializer? That might be worth mentioning in the JavaDoc (if we're doing a CSR anyway...).
-------------
PR: https://git.openjdk.java.net/jdk/pull/7448
More information about the core-libs-dev
mailing list