Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8359669

AttributeList.asList() does not throw IllegalArgumentException when the list contains null

XMLWordPrintable

      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 ----------

            kevinw Kevin Walls
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: