private static SortedMap<String, Object> makeMap(Map<String, ?> items) { if (items == null || items.isEmpty()) throw new IllegalArgumentException("Null or empty items map"); SortedMap<String, Object> map = new TreeMap<String, Object>(); 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 // exception is a historical artifact - an implementation // detail that leaked into the API. } map.put((String) key, items.get(key)); } return map; }