java.jmx

Result of clojure.java.jmx.Bean.getAttribute is not a javax.management.Attribute

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Patch:
    Code and Test
  • Approval:
    Accepted

Description

The documentation suggests that you create a JMX bean (clojure.java.jmx.Bean) by calling clojure.java.jmx/create-bean on a reference to a map whose values are the actual values you want as attributes: for instance, (create-bean (ref {:calls-so-far 0})). However, if you do this, when you get the attribute out using .getAttribute the result is the actual state value, and not the javax.management.Attribute in question as the interface specifies. This also causes a ClassCastException when you try to call .getAttributes or anything else that tries to add the attributes to an AttributeList.

The attached patch fixes this problem by wrapping the state value in a call to Attribute. so that .getAttribute yields an Attribute, and modifies objects->data to descend into Attribute values accordingly. The tests work, and it works for my use case, but I do not know whether this is the right solution in general.

Activity

Hide
Nick Bailey added a comment -

Committed.

Show
Nick Bailey added a comment - Committed.
Hide
Chris Jeris added a comment -

Looks good and works for my use case. Sorry for the delay – I appear not to have email notifications from this JIRA configured correctly.

Show
Chris Jeris added a comment - Looks good and works for my use case. Sorry for the delay – I appear not to have email notifications from this JIRA configured correctly.
Hide
Nick Bailey added a comment -

Updated patch. Look good Chris Jeris?

Show
Nick Bailey added a comment - Updated patch. Look good Chris Jeris?
Hide
Nick Bailey added a comment -

Going to go ahead and update the patch accordingly.

Show
Nick Bailey added a comment - Going to go ahead and update the patch accordingly.
Hide
Nick Bailey added a comment -

Ok, found better documentation here.

http://docs.oracle.com/cd/E19698-01/816-7609/6mdjrf83d/index.html

So getAttribute should be returning an attributes value rather than an actual attribute object. But as I mentioned before, getAttributes should be returning a list of Attribute objects.

Show
Nick Bailey added a comment - Ok, found better documentation here. http://docs.oracle.com/cd/E19698-01/816-7609/6mdjrf83d/index.html So getAttribute should be returning an attributes value rather than an actual attribute object. But as I mentioned before, getAttributes should be returning a list of Attribute objects.
Hide
Nick Bailey added a comment -

The documentation there is somewhat vague. Perhaps that part of the api shouldn't be changed. It seems like at least the .getAttributes implementation at least is wrong though. The documentation for AttributeList is clear that only Attribute objects should be added to the AttributeList, but it looks like all current jvm implementations (or ones we test with) don't do a good job of actually enforcing that.

http://docs.oracle.com/javase/1.5.0/docs/api/javax/management/AttributeList.html

Do we know if any built in dynamic mbeans return Attribute objects or the actual values of a specific attribute?

Show
Nick Bailey added a comment - The documentation there is somewhat vague. Perhaps that part of the api shouldn't be changed. It seems like at least the .getAttributes implementation at least is wrong though. The documentation for AttributeList is clear that only Attribute objects should be added to the AttributeList, but it looks like all current jvm implementations (or ones we test with) don't do a good job of actually enforcing that. http://docs.oracle.com/javase/1.5.0/docs/api/javax/management/AttributeList.html Do we know if any built in dynamic mbeans return Attribute objects or the actual values of a specific attribute?
Hide
Jürgen Hötzel added a comment -

I don't see whats wrong in the implementation of the DynamicMbean interface:

 
({:name getAttribute,                                                                                              
  :return-type java.lang.Object,                                                                                   
  :declaring-class javax.management.DynamicMBean,                                                                  
  :parameter-types [java.lang.String],                                                                             
  :exception-types                                                                                                 
  [javax.management.AttributeNotFoundException                                                                     
   javax.management.MBeanException                                                                                 
   javax.management.ReflectionException],                                                                          
  :flags #{:public :abstract}})       

the return type is

 java.lang.Object
, not
 javax.management.Attribute

Show
Jürgen Hötzel added a comment - I don't see whats wrong in the implementation of the DynamicMbean interface:
 
({:name getAttribute,                                                                                              
  :return-type java.lang.Object,                                                                                   
  :declaring-class javax.management.DynamicMBean,                                                                  
  :parameter-types [java.lang.String],                                                                             
  :exception-types                                                                                                 
  [javax.management.AttributeNotFoundException                                                                     
   javax.management.MBeanException                                                                                 
   javax.management.ReflectionException],                                                                          
  :flags #{:public :abstract}})       

the return type is
 java.lang.Object
, not
 javax.management.Attribute
Hide
Nick Bailey added a comment -

Chris,

Sorry for the delay.

Whats the reason for the addition to objects->data? By that point we've already read the attribute list for a bean and are processing the attribute values right?

Show
Nick Bailey added a comment - Chris, Sorry for the delay. Whats the reason for the addition to objects->data? By that point we've already read the attribute list for a bean and are processing the attribute values right?
Hide
Nick Bailey added a comment -

Chris,

Thanks for submitting a patch for this. I'll be able to review it sometime in the next few days hopefully.

Show
Nick Bailey added a comment - Chris, Thanks for submitting a patch for this. I'll be able to review it sometime in the next few days hopefully.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: