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

java.util.NoSuchElementException thrown in RequiredModelMBean when tracing enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6u4
    • core-svc
    • b26
    • sparc
    • solaris_2.5.1
    • Verified

      The class javax.management.modelmbean.RequiredModelMBean handles a listener in the method addAttributeChangeNotificationListener. The listener has a Vector which is be populated through the provided attributes either through the config file or command line. When no attributes are provided the Vector is empty.

      RequiredModelMBean.java has an unguarded tracing path on line 2223, which directly accesses the attribute vector to retrieve the element information:

        if (tracing());
            trace(ftag, "Set attribute change filter to " +
            ((currFilter.getEnabledAttributes()).firstElement()).toString());

      This leads to a java.util.NoSuchElementException being thrown if their are no attributes.

        To reproduce the issue, run the testcase (below) with the following command line option:

        -Djava.util.logging.config.file=logging.properties

      Where logging.properties is a file containing the following line:

        javax.management.level=FINEST

      You then get the following output when running the testcase:

      c:\>java -Djava.util.logging.config.file=logging.properties MBeanTester
      java.util.NoSuchElementException
              at java.util.Vector.firstElement(Vector.java:442)
              at javax.management.modelmbean.RequiredModelMBean.addAttributeChangeNotificationListener(RequiredModelMBean.java:2255)
              at MBeanTester.main(MBeanTester.java:15)


      Testcase Source:
      --------------------------------------------------------------------
      import javax.management.modelmbean.RequiredModelMBean;
      import javax.management.*;

      public class MBeanTester implements NotificationListener {

          public void handleNotification(Notification n,Object o) {
              System.out.println("Notification"+n);
          }

          public static void main(String[] args) {
              Object o = new Object();
              NotificationListener nl = new MBeanTester();
              try {
                  RequiredModelMBean mbean = new RequiredModelMBean();
                  mbean.addAttributeChangeNotificationListener(nl,null,o);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }

      }
      --------------------------------------------------------------------

            emcmanus Eamonn McManus
            dkorbel David Korbel (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: