On Fri, 20 Jun 2025 18:18:07 GMT, Kevin Walls <kev...@openjdk.org> wrote:

>> src/java.management/share/classes/javax/management/relation/RoleList.java 
>> line 265:
>> 
>>> 263:     @Override
>>> 264:     public boolean add(Object o) {
>>> 265:         checkTypeSafe(o);
>> 
>> Q: Is `null` allowed? The same question applies to the `addAll()` if these 
>> methods allow null to be present in the collection.
>
> The intent here is not to change behaviour regarding nulls.
> Nulls have been permitted, and should stay permitted.
> Other object types (that don't cast to Role, in this file) should fail.
> 
> The Role related files are quite unusual to use, so expect they are mostly 
> used only by the JDK.
> MBean code might more commonly manipulate an AttributeList, and we can still 
> permit nulls in case such code relies on nulls being accepted.

My question was because there are checks for `null` in this class:

public void add(Role role)
        throws IllegalArgumentException {

        if (role == null) {
            throw new IllegalArgumentException("Invalid parameter");
        }
        checkTypeSafe(role);
        super.add(role);
    }

It is kind of confusing and not clear where `null` is allowed and where it is 
not.
Should it be more consistent?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/25856#discussion_r2159655977

Reply via email to