Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4954062

JMX RI 1.2 does not allow ModelMBeans to have custom targetType descriptor value

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 3.5
    • Fix Version/s: 5.0
    • Component/s: core-svc
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b32
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      Name: jl125535 Date: 11/13/2003


      FULL PRODUCT VERSION :
      java version "1.4.2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2-b28)
      Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      FULL OS VERSION :
      Microsoft Windows 2000 [Version 5.00.2195]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      I am running JMX RI 1.2.0 and 1.2.1.

      A DESCRIPTION OF THE PROBLEM :
      The JMX 1.2.x RI does not allow for custom defined targetType descriptor values in ModelMBeans. However, the JMX 1.2 spec (and previous versions) makes it clear that implementations are free to define their own.

        From Page 100:

      "Implementations can also recognize the predefined types ObjectReference, Handle, IOR, EJBHandle, and RMIReference, as well as implementation-defined types."

        From Page 86:

      "The String field encodes the target object type of reference for the managed
      resource. This can be: ObjectReference, Handle, IOR, EJBHandle, or RMIReference. An implementation must support ObjectReference, but need not support the other types. It can also define implementation-specific types."

        From Page 88:

      "Valid values for targetType include, but are not limited to, ObjectReference, Handle, IOR, EJBHandle, and RMIReference."

        To further explain, the specification makes it clear that user software may implement its own RequiredModelMBean. It is this implementation that can, and according to spec is allowed, to provide support for additional targetType values above and beyond the 5 listed in the spec.

        From Page 72:

      "The RequiredModelMBean implementation will always be available, but there can be other implementations of the model MBean available, depending on the needs of the environment in which the JMX agent is installed."

      I wrote my own implementation of a ModelMBean (separate from the RequiredModelMBean that ships with the RI), following the requirements of the JMX 1.2 specification. It supports additional targetType values that are custom. The JMX 1.2.x RI, however, throws an IllegalArgumentException when I try to create a ModelMBeanOperationInfo with a descriptor that has a custom targetType field value. It seems it only allows for those 5 types specified in the specification but no others.

      As a side note, the MX4J implementation of the JMX 1.1 spec does not have this bug and neither does either JMX RI implementations. When I create ModelMBeans using my own RequiredModelMBean implementation, I can successfully define custom targetTypes using those. This seems to be a bug introduced in JMX RI 1.2.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Create a descriptor with a custom targetType field
      2) Create a ModelMBeanOperationInfo with that descriptor

      // I just show the targetType field for clarity; to get this to really run,
      // you must also add all the non-optional fields like 'name' as well
      Descriptor desc = new DescriptorSupport(new String[] { "targetType=Custom" } );

      ModelMBeanOperationInfo op =
         new ModelMBeanOperationInfo("op", "description", new MBeanParameterInfo[0], Void.TYPE.getName( ), 1, desc );

      That constructor of ModelMBeanOperationInfo with throw an IllegalArgumentException.

      See below for a full executable test case.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect the constructor to successfully instantiate my ModelMBeanOperationInfo object. I would expect that the RI's RequiredModelMBean to throw an exception should it be asked to invoke that operation due to invalid target type (InvalidTargetTypeException), however, that check should not be made in the ModelMBeanOperationInfo constructor. The reason for this is clear - this ModelMBeanOperationInfo may be used by a custom ModelMBean implementation that DOES understand how to invoke the given targetType.
      ACTUAL -
      See error messages below for the actual exception stack trace.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      The exception throw by the given executable test case is:

      javax.management.RuntimeOperationsException: Exception occured in ModelMBeanOperationInfo constructor
      at javax.management.modelmbean.ModelMBeanOperationInfo.<init>(ModelMBeanOperationInfo.java:287)
      at com.hp.wsm.impact.sba.jmx.TargetTypeBug.main(TargetTypeBug.java:24)
      Caused by: java.lang.IllegalArgumentException: Invalid descriptor passed in parameter
      ... 2 more
      Exception in thread "main"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.management.Descriptor;
      import javax.management.MBeanParameterInfo;
      import javax.management.modelmbean.ModelMBeanOperationInfo;

      public class TargetTypeBug
      {
         public static void main(String[] args)
         {
            Descriptor desc;
            ModelMBeanOperationInfo op;
            // create a valid op info with default descriptor fields
            op = new ModelMBeanOperationInfo("op", "",
                    new MBeanParameterInfo[0], "void", 1);
            desc = op.getDescriptor(); // contains default set of fields now

            // set targetType to a value that all implementation must support
            desc.setField("targetType", "ObjectReference");
            op = new ModelMBeanOperationInfo("op", "",
                    new MBeanParameterInfo[0], "void", 1, desc);

            // set targetType to a custom value
            // according to spec, this should be OK but
            // a bug in JMX RI 1.2.x throws exception
            desc.setField("targetType", "Custom");
            op = new ModelMBeanOperationInfo("op", "",
                    new MBeanParameterInfo[0], "void", 1, desc);
         }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      The only thing I can think of is for my ModelMBean implementation to not use "targetType" as the field name... I would have to use something non-compliant like "customTargetType". Obviously, because this is non-JMX compliant, it is something that should be avoided and considered a temporary fix only.

      Proposed solution is to eliminate the if-statement that is checking the value of targetType. From the JMX RI 1.2.0 source code of ModelMBeanOperationInfo.java:

          } else {
      if ( !((String)targetValue).equalsIgnoreCase("ObjectReference") &&
      !((String)targetValue).equalsIgnoreCase("Handle") &&
      !((String)targetValue).equalsIgnoreCase("EJBHandle") &&
      !((String)targetValue).equalsIgnoreCase("IOR") &&
      !((String)targetValue).equalsIgnoreCase("RMIReference")) {

      results = false;
      badField="targetType";
             }
      (Incident Review ID: 207846)
      ======================================================================
      ###@###.### 2003-11-13

        Attachments

          Activity

            People

            Assignee:
            emcmanus Eamonn McManus
            Reporter:
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: