JDK-6675768 : java.util.NoSuchElementException thrown in RequiredModelMBean when tracing enabled
  • Type: Bug
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6u4
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.5.1
  • CPU: sparc
  • Submitted: 2008-03-14
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b26Fixed
Related Reports
Relates :  
Description
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();
        }
    }

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

Comments
EVALUATION This should happen rarely in practice. To trigger the problem, you must (a) have logging enabled, (b) call the unusual method RequiredModelMBean.addAttributeChangeNotificationListener, (c) with a null argument (to signify any attribute), (d) on an MBean that has no attributes. Nevertheless the fix is straightforward and we should certainly apply it.
19-03-2008