diff -r 460e37d40f12 -r acaa49a2768a jdk/src/share/classes/javax/management/openmbean/CompositeDataSupport.java --- a/jdk/src/share/classes/javax/management/openmbean/CompositeDataSupport.java Wed Oct 21 16:28:57 2009 +0200 +++ b/jdk/src/share/classes/javax/management/openmbean/CompositeDataSupport.java Wed Oct 21 17:33:18 2009 +0200 @@ -92,16 +92,16 @@ * @param itemNames itemNames must list, in any order, all the * item names defined in compositeType; the order in which the * names are listed, is used to match values in itemValues[]; must - * not be null. + * not be null or empty. * * @param itemValues the values of the items, listed in the same order as * their respective names in itemNames; each item value can be * null, but if it is non-null it must be a valid value for the open type * defined in compositeType for the corresponding item; must be of - * the same size as itemNames; must not be null. + * the same size as itemNames; must not be null or empty. * * @throws IllegalArgumentException compositeType is null, or - * itemNames[] or itemValues[] is null, or one + * itemNames[] or itemValues[] is null or empty, or one * of the elements in itemNames[] is a null or empty string, or * itemNames[] and itemValues[] are not of the same size. * @@ -124,6 +124,8 @@ if (itemNames == null || itemValues == null) throw new IllegalArgumentException("Null itemNames or itemValues"); + if (itemNames.length == 0 || itemValues.length == 0) + throw new IllegalArgumentException("Empty itemNames or itemValues"); if (itemNames.length != itemValues.length) { throw new IllegalArgumentException( "Different lengths: itemNames[" + itemNames.length + @@ -154,10 +156,10 @@ * must not be null. * @param items the mappings of all the item names to their values; * items must contain all the item names defined in compositeType; - * must not be null. + * must not be null or empty. * * @throws IllegalArgumentException compositeType is null, or - * items is null, or one of the keys in items is a null + * items is null or empty, or one of the keys in items is a null * or empty string. * @throws OpenDataException items' size differs from the * number of items defined in compositeType, or one of the @@ -167,8 +169,6 @@ * compositeType. * @throws ArrayStoreException one or more keys in items is not of * the class java.lang.String. - * - * @see #toMap */ public CompositeDataSupport(CompositeType compositeType, Map items) @@ -177,13 +177,13 @@ } private static SortedMap makeMap(Map items) { - if (items == null) - throw new IllegalArgumentException("Null items map"); - if (items.containsKey(null) || items.containsKey("")) - throw new IllegalArgumentException("Null or empty item name"); + if (items == null || items.isEmpty()) + throw new IllegalArgumentException("Null or empty items map"); SortedMap map = new TreeMap(); for (Object key : items.keySet()) { + if (key == null || key.equals("")) + throw new IllegalArgumentException("Null or empty item name"); if (!(key instanceof String)) { throw new ArrayStoreException("Item name is not string: " + key); // This can happen because of erasure. The particular @@ -329,54 +329,6 @@ } /** - *

Returns a Map representing the contents of the given CompositeData. - * Each item in the CompositeData is represented by an entry in the map, - * where the name and value of the item are the key and value of the entry. - * The returned value is modifiable but modifications to it have no effect - * on the original CompositeData.

- * - *

For example, if you have a CompositeData {@code cd1} and you want - * to produce another CompositeData {@code cd2} which is the same except - * that the value of its {@code id} item has been changed to 253, you - * could write:

- * - *
-     * CompositeData cd1 = ...;
-     * {@code Map} map = CompositeDataSupport.toMap(cd1);
-     * assert(map.get("id") instanceof Integer);
-     * map.put("id", 253);
-     * CompositeData cd2 = {@link #CompositeDataSupport(CompositeType, Map)
-     * new CompositeDataSupport}(cd1.getCompositeType(), map);
-     * 
- * - *

Logically, this method would be a method in the {@link CompositeData} - * interface, but cannot be for compatibility reasons.

- * - * @param cd the CompositeData to convert to a Map. - * - * @return a Map that is a copy of the contents of {@code cd}. - * - * @throws IllegalArgumentException if {@code cd} is null. - * - * @see #CompositeDataSupport(CompositeType, Map) - */ - public static Map toMap(CompositeData cd) { - if (cd == null) - throw new IllegalArgumentException("Null argument"); - - // If we really wanted, we could check whether cd is a - // CompositeDataSupport and return a copy of cd.contents if so, - // but I don't think that would be substantially faster. - Map map = new LinkedHashMap(); - CompositeType ct = cd.getCompositeType(); - for (String key : ct.keySet()) { - Object value = cd.get(key); - map.put(key, value); - } - return map; - } - - /** * Compares the specified obj parameter with this * CompositeDataSupport instance for equality. *