-
Bug
-
Resolution: Fixed
-
P4
-
6u4
-
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();
}
}
}
--------------------------------------------------------------------
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();
}
}
}
--------------------------------------------------------------------
- relates to
-
JDK-6471865 Unable to create a modelmbean.DescriptorSupport with debugging ON
- Resolved