RFR: 8371953: Document null handling in core reflection APIs [v3]
David Holmes
dholmes at openjdk.org
Wed Nov 19 06:43:20 UTC 2025
On Sun, 16 Nov 2025 08:45:38 GMT, Alan Bateman <alanb at openjdk.org> wrote:
>> Chen Liang has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains 11 additional commits since the last revision:
>>
>> - From review
>> - Merge branch 'master' of https://github.com/openjdk/jdk into fix/core-reflection-null-checks
>> - Rephrase for parameterTypes contains null
>> - Rename tests to be more specific
>> - Split annotated type new checks to another patch
>> - Redundant
>> - Test and more fixes
>> - Copyright years
>> - Testing
>> - Merge branch 'master' of https://github.com/openjdk/jdk into fix/core-reflection-null-checks
>> - ... and 1 more: https://git.openjdk.org/jdk/compare/edfda06d...51ef5789
>
> src/java.base/share/classes/java/lang/Class.java line 3839:
>
>> 3837: */
>> 3838: public boolean isNestmateOf(Class<?> c) {
>> 3839: Objects.requireNonNull(c);
>
> So the behavior change here is calling isNestmateOf(null) on a class object for a primitive or array class will throw NPE when it didn't throw it previously. Technically an incompatible change but I agree it's in the weeds when it comes to impact.
A null check was not considered necessary for this API. If you ask `c.isNestMateOf(null)` the answer is `false`. We chose not to report you had "asked a stupid question".
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28336#discussion_r2540733026
More information about the core-libs-dev
mailing list