RFR: 8359809: AttributeList, RoleList and UnresolvedRoleList should never accept other types of Object
Kevin Walls
kevinw at openjdk.org
Fri Jun 20 18:20:28 UTC 2025
On Fri, 20 Jun 2025 17:40:27 GMT, Serguei Spitsyn <sspitsyn at openjdk.org> wrote:
>> The classes javax.management.AttributeList, and javax.management.relation.RoleList and UnresolvedRoleList, have a historical feature where they accept objects of the wrong type, and only check for wrong objects when the "asList()" method is called.
>>
>> This feature should be removed, and these classes should never accept the wrong kind of Object.
>
> 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.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25856#discussion_r2159481021
More information about the serviceability-dev
mailing list