codahale/metrics — Issue #175: "Use MXBeans for JMX" Breaks Gauge Import
Author: pdoubleya
Created: 2012-03-01 12:25:50+00:00
State: open

Running from trunk, the fix in https://github.com/codahale/metrics/commit/90396fcd25486ab58315a12863e3e6a29e4fe6c6 causes an exception to be thrown when a Gauge is registered. The Gauge looks something like this
```java
Metrics.newGauge(oomMName, new Gauge() {
@Override public Integer value() {
final File logDir = new File(System.getProperty("log.dir"));
final File[] list = logDir.listFiles((FileFilter) new NameFileFilter("heap.dump"));
return list == null ? 0 : list.length;
}
})
```

The problem appears in JDK code which I can follow through the debugger, but which doesn't include debug symbols - not sure what is going wrong, exactly. The problem shows up in com.sun.jmx.mbeanserver.ConvertingMethod#from, when it tries to determine the return type of, I think, the getValue() method. To work around this I reverted the commit locally and it works. I don't have a fix.

Stack trace is:
2012-03-01 13:06:39,830 [main] WARN com.yammer.metrics.reporting.JmxReporter Error processing tsc:type=pages,scope=search,name=async-callback-task
javax.management.NotCompliantMBeanException: com.yammer.metrics.reporting.JmxReporter$GaugeMXBean: Method com.yammer.metrics.reporting.JmxReporter$GaugeMXBean.getValue has parameter or return type that cannot be translated into an open type
at com.sun.jmx.mbeanserver.Introspector.throwException(Introspector.java:412)
at com.sun.jmx.mbeanserver.MBeanAnalyzer.(MBeanAnalyzer.java:101)
at com.sun.jmx.mbeanserver.MBeanAnalyzer.analyzer(MBeanAnalyzer.java:87)
at com.sun.jmx.mbeanserver.MXBeanIntrospector.getAnalyzer(MXBeanIntrospector.java:53)
at com.sun.jmx.mbeanserver.MBeanIntrospector.getPerInterface(MBeanIntrospector.java:163)
at com.sun.jmx.mbeanserver.MBeanSupport.(MBeanSupport.java:147)
at com.sun.jmx.mbeanserver.MXBeanSupport.(MXBeanSupport.java:48)
at com.sun.jmx.mbeanserver.Introspector.makeDynamicMBean(Introspector.java:184)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:915)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:482)
at com.yammer.metrics.reporting.JmxReporter.registerBean(JmxReporter.java:451)
at com.yammer.metrics.reporting.JmxReporter.processGauge(JmxReporter.java:429)
at com.yammer.metrics.reporting.JmxReporter.processGauge(JmxReporter.java:16)
at com.yammer.metrics.core.Gauge.processWith(Gauge.java:28)
at com.yammer.metrics.reporting.JmxReporter.onMetricAdded(JmxReporter.java:386)
at com.yammer.metrics.core.MetricsRegistry.notifyMetricAdded(MetricsRegistry.java:516)
at com.yammer.metrics.core.MetricsRegistry.getOrAdd(MetricsRegistry.java:491)
at com.yammer.metrics.core.MetricsRegistry.newGauge(MetricsRegistry.java:79)
at com.yammer.metrics.Metrics.newGauge(Metrics.java:70)
at com.example.App.(App.java:183)
Caused by: java.lang.IllegalArgumentException: Method com.yammer.metrics.reporting.JmxReporter$GaugeMXBean.getValue has parameter or return type that cannot be translated into an open type
at com.sun.jmx.mbeanserver.ConvertingMethod.from(ConvertingMethod.java:32)
at com.sun.jmx.mbeanserver.MXBeanIntrospector.mFrom(MXBeanIntrospector.java:63)
at com.sun.jmx.mbeanserver.MXBeanIntrospector.mFrom(MXBeanIntrospector.java:33)
at com.sun.jmx.mbeanserver.MBeanAnalyzer.initMaps(MBeanAnalyzer.java:118)
at com.sun.jmx.mbeanserver.MBeanAnalyzer.(MBeanAnalyzer.java:99)
... 25 more
Caused by: javax.management.openmbean.OpenDataException: Cannot convert type: class java.lang.Object
at com.sun.jmx.mbeanserver.OpenConverter.openDataException(OpenConverter.java:1411)
at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:264)
at com.sun.jmx.mbeanserver.ConvertingMethod.(ConvertingMethod.java:184)
at com.sun.jmx.mbeanserver.ConvertingMethod.from(ConvertingMethod.java:27)
... 29 more
Caused by: javax.management.openmbean.OpenDataException: Can't map java.lang.Object to an open data type
at com.sun.jmx.mbeanserver.OpenConverter.makeCompositeConverter(OpenConverter.java:454)
at com.sun.jmx.mbeanserver.OpenConverter.makeConverter(OpenConverter.java:293)
at com.sun.jmx.mbeanserver.OpenConverter.toConverter(OpenConverter.java:262)
... 31 more