This patch corrects a mistake in the JMX translator for MXBeans. It incorrectly casts both Lists and Sets to List rather than Collection. This also replaces the ad-hoc method of obtaining the type with the correct way using ParameterizedType. I assume this didn't work before due to a lack of support in the VMs.
ChangeLog: 2008-02-21 Andrew John Hughes <[EMAIL PROTECTED]> * gnu/javax/management/Translator.java: (fromJava(Object[],Method)): Don't cast to Class<?>. (fromJava(Object,Type)): Use ParameterizedType and don't assume that List will work for Sets. -- Andrew :) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint = F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8
Index: gnu/javax/management/Translator.java =================================================================== RCS file: /sources/classpath/classpath/gnu/javax/management/Translator.java,v retrieving revision 1.5 diff -u -3 -p -u -r1.5 Translator.java --- gnu/javax/management/Translator.java 2 Dec 2007 01:11:04 -0000 1.5 +++ gnu/javax/management/Translator.java 21 Feb 2008 19:52:36 -0000 @@ -40,11 +40,14 @@ package gnu.javax.management; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Proxy; import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -93,7 +96,7 @@ public final class Translator Type[] gtypes = method.getGenericParameterTypes(); Object[] otypes = new Object[jtypes.length]; for (int a = 0; a < jtypes.length; ++a) - otypes[a] = fromJava(jtypes[a], (Class<?>) gtypes[a]); + otypes[a] = fromJava(jtypes[a], gtypes[a]); return otypes; } @@ -132,11 +135,10 @@ public final class Translator if (jtype instanceof List || jtype instanceof Set || jtype instanceof SortedSet) { - String elemType = tName.substring(tName.indexOf("<") + 1, - tName.indexOf(">")).trim(); if (jtype instanceof SortedSet) { - Class<?> elemClass = Class.forName(elemType); + ParameterizedType ptype = (ParameterizedType) type; + Class<?> elemClass = (Class<?>) ptype.getActualTypeArguments()[0]; if (!Comparable.class.isAssignableFrom(elemClass)) throw new IllegalArgumentException(jtype + " has a " + "non-comparable element " + @@ -145,11 +147,13 @@ public final class Translator throw new IllegalArgumentException(jtype + " does not " + "use natural ordering."); } - List elems = (List) jtype; - Object[] celems = new Object[elems.size()]; - for (int a = 0; a < elems.size(); ++a) + Collection<Object> elems = (Collection<Object>) jtype; + int numElems = elems.size(); + Object[] celems = new Object[numElems]; + Iterator<Object> i = elems.iterator(); + for (int a = 0; a < numElems; ++a) { - Object elem = elems.get(a); + Object elem = i.next(); celems[a] = fromJava(elem, elem.getClass()); } return makeArraySpecific(celems);
signature.asc
Description: Digital signature