JDK-8359669 : AttributeList.asList() does not throw IllegalArgumentException when the list contains null
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 17
  • Priority: P3
  • Status: New
  • Resolution: Unresolved
  • OS: generic
  • CPU: generic
  • Submitted: 2025-06-11
  • Updated: 2025-06-16
Description
A DESCRIPTION OF THE PROBLEM :
The Javadoc for AttributeList.asList() states:
“Throws: IllegalArgumentException – if this AttributeList contains an element that is not an Attribute.”

A null reference is not an instance of javax.management.Attribute, therefore asList() should throw IllegalArgumentException when the underlying list contains null.

REGRESSION : Last worked in version 17


---------- BEGIN SOURCE ----------
import javax.management.Attribute;
import javax.management.AttributeList;

public class AttributeListNullBug {
    public static void main(String[] args) {
        AttributeList list = new AttributeList();
        list.add(null);                         // insert invalid element

        try {
            list.asList();                     // should fail
            System.out.println(null instanceof Attribute); // prints false
            throw new RuntimeException(
                "null is not an Attribute – asList() should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException e) {
            System.out.println("Caught expected IllegalArgumentException: " + e);
        }
    }
}
---------- END SOURCE ----------


Comments
AttributeList may require its spec updates to clearly indicate if null elements are allowed or not, so broader than the observation on the asList method.
16-06-2025