This fixes a bug with the translator not examining
arbitrary types correctly (i.e. the default if the type
isn't one of the basic types, an enum or some type of collection).

ChangeLog:

2007-12-02  Andrew John Hughes  <[EMAIL PROTECTED]>

        PR classpath/34276:
        * gnu/javax/management/Translator.java:
        (translate(String)): Select only public methods
        from a composite type, try this translation in all
        cases and exit only when no fields are translated.

-- 
Andrew :-)

Escape the Java Trap with GNU Classpath!
http://www.gnu.org/philosophy/java-trap.html
public class gcj extends Freedom implements Java { ... }
Index: gnu/javax/management/Translator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/management/Translator.java,v
retrieving revision 1.4
diff -u -3 -p -u -r1.4 Translator.java
--- gnu/javax/management/Translator.java	6 Apr 2007 15:45:08 -0000	1.4
+++ gnu/javax/management/Translator.java	2 Dec 2007 01:03:13 -0000
@@ -39,6 +39,7 @@ package gnu.javax.management;
 
 import java.lang.reflect.Array;
 import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
 import java.lang.reflect.Proxy;
 import java.lang.reflect.Type;
 
@@ -440,33 +441,6 @@ public final class Translator
 						 SimpleType.STRING,
 						 null, names);
       }
-    try
-      {
-	c.getMethod("from", new Class[] { CompositeData.class });
-	Method[] methods = c.getDeclaredMethods();
-	List<String> names = new ArrayList<String>();
-	List<OpenType> types = new ArrayList<OpenType>();
-	for (int a = 0; a < methods.length; ++a)
-	  {
-	    String name = methods[a].getName();
-	    if (name.startsWith("get"))
-	      {
-		names.add(name.substring(3));
-		types.add(getTypeFromClass(methods[a].getReturnType()));
-	      }
-	  }
-	String[] fields = names.toArray(new String[names.size()]);
-	CompositeType ctype = new CompositeType(c.getName(), c.getName(),
-						fields, fields,
-						types.toArray(new OpenType[types.size()]));
-	return new OpenMBeanParameterInfoSupport("TransParam",
-						 "Translated parameter",
-						 ctype);
-      }
-    catch (NoSuchMethodException e)
-      {
-	/* Ignored; we expect this if this isn't a from(CompositeData) class */
-      }
     if (c.isArray())
       {
 	int depth;
@@ -478,7 +452,35 @@ public final class Translator
 						 new ArrayType(depth, ot)
 						 );
       }
-    throw new InternalError("The type used does not have an open type translation.");
+    Method[] methods = c.getDeclaredMethods();
+    List<String> names = new ArrayList<String>();
+    List<OpenType> types = new ArrayList<OpenType>();
+    for (int a = 0; a < methods.length; ++a)
+      {
+	String name = methods[a].getName();
+	if (Modifier.isPublic(methods[a].getModifiers()))
+	  {
+	    if (name.startsWith("get"))
+	      {
+		names.add(name.substring(3));
+		types.add(getTypeFromClass(methods[a].getReturnType()));
+	      }
+	    else if (name.startsWith("is"))
+	      {
+		names.add(name.substring(2));
+		types.add(getTypeFromClass(methods[a].getReturnType()));
+	      }
+	  }
+      }
+    if (names.isEmpty())
+      throw new OpenDataException("The type used does not have an open type translation.");
+    String[] fields = names.toArray(new String[names.size()]);
+    CompositeType ctype = new CompositeType(c.getName(), c.getName(),
+					    fields, fields,
+					    types.toArray(new OpenType[types.size()]));
+    return new OpenMBeanParameterInfoSupport("TransParam",
+					     "Translated parameter",
+					     ctype);
   }
 
   /**

Attachment: signature.asc
Description: Digital signature

Reply via email to