This fixes a couple of bugs found running the updated
TestBeans example.  But there are still more lurking... :(

ChangeLog:

2007-11-30  Andrew John Hughes  <[EMAIL PROTECTED]>

        PR classpath/34276:
        * gnu/java/lang/management/BeanImpl.java:
        (getDescription(MBeanConstructorInfo,MBeanParameterInfo,int)):
        Added to provide a default description if the current one is null.
        (getDescription(MBeanOperationInfo,MBeanParameterInfo,int)):
        Likewise.
        (getParameterName(MBeanConstructorInfo,MBeanParameterInfo,int)):
        Likewise for the name.
        (getParameterName(MBeanOperationInfo,MBeanParameterInfo,int)):
        Likewise.
        * gnu/javax/management/Server.java:
        (getMBeanInfo()): Try using a StandardMBean wrapper if reflection
        fails to find getMBeanInfo().

-- 
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/java/lang/management/BeanImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/lang/management/BeanImpl.java,v
retrieving revision 1.16
diff -u -3 -p -u -r1.16 BeanImpl.java
--- gnu/java/lang/management/BeanImpl.java	1 Nov 2007 20:06:55 -0000	1.16
+++ gnu/java/lang/management/BeanImpl.java	30 Nov 2007 01:10:08 -0000
@@ -318,6 +318,90 @@ public class BeanImpl
     return (MBeanInfo) openInfo;
   }
 
+  /**
+   * Override this method so as to prevent the description of a constructor's
+   * parameter being @code{null}.  Open MBeans can not have @code{null} descriptions,
+   * but one will occur as the names of parameters aren't stored for reflection.
+   * 
+   * @param constructor the constructor whose parameter needs describing.
+   * @param parameter the parameter to be described.
+   * @param sequenceNo the number of the parameter to describe.
+   * @return a description of the constructor's parameter.
+   */
+  protected String getDescription(MBeanConstructorInfo constructor,
+				  MBeanParameterInfo parameter,
+				  int sequenceNo)
+  {
+    String desc = parameter.getDescription();
+    if (desc == null)
+      return "param" + sequenceNo;
+    else
+      return desc;
+  }
+
+  /**
+   * Override this method so as to prevent the description of an operation's
+   * parameter being @code{null}.  Open MBeans can not have @code{null} descriptions,
+   * but one will occur as the names of parameters aren't stored for reflection.
+   * 
+   * @param operation the operation whose parameter needs describing.
+   * @param parameter the parameter to be described.
+   * @param sequenceNo the number of the parameter to describe.
+   * @return a description of the operation's parameter.
+   */
+  protected String getDescription(MBeanOperationInfo operation,
+				  MBeanParameterInfo parameter,
+				  int sequenceNo)
+  {
+    String desc = parameter.getDescription();
+    if (desc == null)
+      return "param" + sequenceNo;
+    else
+      return desc;
+  }
+
+  /**
+   * Override this method so as to prevent the name of a constructor's
+   * parameter being @code{null}.  Open MBeans can not have @code{null} names,
+   * but one will occur as the names of parameters aren't stored for reflection.
+   * 
+   * @param constructor the constructor whose parameter needs a name.
+   * @param parameter the parameter to be named.
+   * @param sequenceNo the number of the parameter to name.
+   * @return a description of the constructor's parameter.
+   */
+  protected String getParameterName(MBeanConstructorInfo constructor,
+				    MBeanParameterInfo parameter,
+				    int sequenceNo)
+  {
+    String name = parameter.getName();
+    if (name == null)
+      return "param" + sequenceNo;
+    else
+      return name;
+  }
+
+  /**
+   * Override this method so as to prevent the name of an operation's
+   * parameter being @code{null}.  Open MBeans can not have @code{null} names,
+   * but one will occur as the names of parameters aren't stored for reflection.
+   * 
+   * @param operation the operation whose parameter needs a name.
+   * @param parameter the parameter to be named.
+   * @param sequenceNo the number of the parameter to name.
+   * @return a description of the operation's parameter.
+   */
+  protected String getParameterName(MBeanOperationInfo operation,
+				    MBeanParameterInfo parameter,
+				    int sequenceNo)
+  {
+    String name = parameter.getName();
+    if (name == null)
+      return "param" + sequenceNo;
+    else
+      return name;
+  }
+
   public MBeanInfo getMBeanInfo()
   {
     super.getMBeanInfo();
Index: gnu/javax/management/Server.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/management/Server.java,v
retrieving revision 1.5
diff -u -3 -p -u -r1.5 Server.java
--- gnu/javax/management/Server.java	1 Nov 2007 20:06:56 -0000	1.5
+++ gnu/javax/management/Server.java	30 Nov 2007 01:10:09 -0000
@@ -1036,8 +1036,15 @@ public class Server
       }
     catch (NoSuchMethodException e)
       {
-	throw new IntrospectionException("The getMBeanInfo method " + 
-					 "could not be found.");
+	try
+	  {
+	    return new StandardMBean(bean, null).getMBeanInfo();
+	  }
+	catch (NotCompliantMBeanException ex)
+	  {
+	    throw new IntrospectionException("An error occurred in executing " +
+					     "getMBeanInfo on the bean: " + ex + ".");
+	  }
       }
     catch (IllegalAccessException e)
       {

Reply via email to