On 19.6.2015 00:02, Daniel Fuchs wrote:
On 6/18/15 7:16 PM, Jaroslav Bachorik wrote:
On 18.6.2015 18:47, Daniel Fuchs wrote:
Hi Jaroslav,
I haven't looked at the code, but if I understand well,
that would be a spec change.
Attribute names are case sensitive in JMX.
getFoo() => attribute named "Foo"
getfoo() => attribute named "foo"
Are you proposing to change that?
In this case it is an even bigger mess. This would work as long as you
don't go through the JavaBeans introspector. The property descriptor
generated for the "getFoo" method will be named "foo" and it is
indistinguishable from "getfoo". Therefore, when you are trying to
reach this attribute as "Foo" the JavaBeans introspector will not
resolve the getter name. The SimpleIntrospector, on the other hand, will.
I am proposing to change the SimpleIntrospector so it behaves exactly
as the JavaBeans introspector. But it seems that even that might be
considered a specification change :/
In the JMX 1.4 specification - section 2.2.2.3:
https://docs.oracle.com/javase/8/docs/technotes/guides/jmx/JMX_1_4_specification.pdf
<<
2.2.2.3 Case Sensitivity
All attribute and operation names derived from these design patterns are
case-
sensitive. For example, this means that the methods 'getstate' and
'setState'
define two attributes, one called 'state' that is read-only, and one called
'State' that is write-only.
While case sensitivity applies directly to component names of standard
MBeans, it is
also applicable to all component names of all types of MBeans, standard
or dynamic.
In general, all names of classes, attributes, operations, methods, and
internal
elements defined in the JMX specification are case sensitive, whether
they appear as
data or as functional code when they are manipulated by management
operations.
>>
I know, I checked the spec. The problem is that the JavaBeans
Introspector, which may get used internally in the JMX code, doesn't
follow this spec.
Try this code:
```
public static class BeanClass1 {
public int getAttribute() {return 0;}
public int getattribute() {return 1;}
}
public static class BeanClass2 {
public int getAttribute() {return 0;}
}
public static void main(String[] args) throws Exception {
System.err.println("=== BeanClass1");
printInfo(Introspector.getBeanInfo(BeanClass1.class));
System.err.println("=== BeanClass2");
printInfo(Introspector.getBeanInfo(BeanClass2.class));
}
private static void printInfo(BeanInfo bi) {
for(PropertyDescriptor pd : bi.getPropertyDescriptors()) {
System.err.println("*** " + pd.getName() + " : " +
pd.getReadMethod().getName());
}
}
```
According to the JMX spec there should be 2 attributes: 'attribute' and
'Attribute'
However, there is only one attribute resolved by the JavaBeans
Introspector and it is 'attribute'. Furthermore, the 'getattribute'
method is chosen as the getter method, rather counter-intuitively.
Anyway, this specification aspect doesn't seem to be enforced neither by
the JTREG test suite nor the JCK tests. I successfully ran jdk_jmx JTREG
testset and api/javax_management JCK suite on my patched version of JDK.
-JB-
-- daniel
-JB-
best regards,
-- daniel
On 18/06/15 18:39, Jaroslav Bachorik wrote:
Please, review the following change
Issue : https://bugs.openjdk.java.net/browse/JDK-8129215
Webrev: http://cr.openjdk.java.net/~jbachorik/8129215/webrev.00
The JMX Introspector will try to use the JavaBeans introspector
whenever
possible, delegating the requests for the property getter/setter
methods. However, when the JavaBeans introspector is not available
(modules) the JMX Introspector falls back to its own simple, reflection
based, algorithm.
The simple algorithm does not enforce the rule of property names
starting with a lower-case letter. This might lead to situations when
the simple introspector provides the getter method for an attribute the
JavaBeans introspector would not (eg. 'Attribute' attribute)
This patch changes the simple introspector behaviour to conform to the
one of the JavaBeans introspector. Also, it makes the simple
introspector called only when the JavaBeans introspector is not
available - and not when the JavaBeans introspector fails to resolve a
property getter.
Thanks,
-JB-