FULL PRODUCT VERSION : java version "1.7.0" Java(TM) SE Runtime Environment (build 1.7.0-b147) Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode) ADDITIONAL OS VERSION INFORMATION : Linux, windows 7 64 bit, verified bug in openjdk source code A DESCRIPTION OF THE PROBLEM : getPlatformManagementInterfaces throws an exception when it attempts to populate a TreeSet of Class objects. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : The below class will always throw an exception: public class Fail { public static void main(String[] args) { for (Class<?> c : java.lang.management.ManagementFactory.getPlatformManagementInterfaces()) { System.out.println(c); } } } EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - The method should successfully return the collection of interfaces it says it will return instead of always failing. ACTUAL - $ javac -cp . Fail.java && java -cp . Fail Exception in thread "main" java.lang.ClassCastException: java.lang.Class cannot be cast to java.lang.Comparable at java.util.TreeMap.compare(TreeMap.java:1188) at java.util.TreeMap.put(TreeMap.java:531) at java.util.TreeSet.add(TreeSet.java:255) at java.lang.management.ManagementFactory.getPlatformManagementInterfaces(ManagementFactory.java:792) at Fail.main(Fail.java:5) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public class Fail { public static void main(String[] args) { for (Class<?> c : java.lang.management.ManagementFactory.getPlatformManagementInterfaces()) { System.out.println(c); } } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : The data being accessed cannot be retrieved from outside the java.lang.management package. The fix should be trivial (either use a HashSet instead of a TreeSet, or if sorting is really deemed desirable, provide a comparator for the treeset to use.)
|