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

Attribute type check is too restrictive in RequiredModelMBean.getAttribute()

    Details

    • Subcomponent:
    • Resolved In Build:
      b31
    • CPU:
      x86
    • OS:
      windows_2000

      Backports

        Description

        Name: gm110360 Date: 05/06/2004


        FULL PRODUCT VERSION :
        jdk 1.5.0 beta 1
        jmx RI 1.2.1

        A DESCRIPTION OF THE PROBLEM :
        The method getAttribute(String attribute) from RequiredModelMBean checks at runtime that the actual class of the attribute is the same as the one declared in ModelMBeanAttributeInfo.
        However, this check is too restrictive : it only succeeds if the class is exactly the same or if it is a primitive type.
        But what about interfaces or sub-classes ? For example, I want to return a map. My accessor declares a return type "java.util.Map", but within the method I return a "java.util.Hashtable", which implements "java.util.Map". Then an exception is thrown, although this should work.
        The problem is the same when declaring a return type "MyClass" and actually returning an object of type "MySubclass", which extends "MyClass".

        The specification is not very clear on this point. But it doesn't say anywhere that the declared return type should be EXACTLY the same as the actual return object type. I think it rather means that both types should be consistent or compatible.

        A simple way to correct that would be to replace the "equals()" with "instanceof" for the type check in the code of getAttribute(String attribute)


        ps: Looking at the source code from RequiredModelMBean, the method invoke(...) used to include the same kind of check, but it has been commented out in the source code.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        1) Declare a class with the following method :

        public java.util.Map getMap() { return new java.util.Hashtable(); }

        2) Create a ModelMBeanInfo with the following ModelMBeanAttributeInfo :

        ModelMBeanAttributeInfo("map", "a map attribute", /* the method above goes here */, null)

        3) Register the class in the MBeanServer through a ModelMBean, with the following ObjectName :

        "MyDomain:myattribute=myclass"

        4) get the MBeanServer and do :

        mBeanServer.getAttribute("MyDomain:myattribute=myclass", "map")

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        an object java.util.Hashtable should be returned
        ACTUAL -
        an InvalidAttributeValueException with the message "Wrong value type received for get attribute", wrapped in an MBeanException

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        see Actual Result

        REPRODUCIBILITY :
        This bug can be reproduced always.

        CUSTOMER SUBMITTED WORKAROUND :
        It is still possible to get the value of the attribute by calling the operation with "invoke", but this is not a real workaround.
        (Incident Review ID: 261196)
        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  lmalvent Luis-Miguel Alventosa (Inactive)
                  Reporter:
                  gmanwanisunw Girish Manwani (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: