apache/kafka · warning · UnsupportedOperationException
Set not allowed.
Error message
Set not allowed.
What it means
Thrown by the KafkaMbean DynamicMBean.invoke() implementation in JmxReporter. Kafka exposes its metrics to JMX as read-only MBeans: only attribute reads (getAttribute/getAttributes) and getMBeanInfo are supported. Any attempt by a JMX client to invoke a named operation on the MBean hits this guard. It is the library's way of signalling that metrics are observable but not remotely mutable.
Source
Thrown at clients/src/main/java/org/apache/kafka/common/metrics/JmxReporter.java:282
MBeanAttributeInfo[] attrs = new MBeanAttributeInfo[metrics.size()];
int i = 0;
for (Map.Entry<String, KafkaMetric> entry : this.metrics.entrySet()) {
String attribute = entry.getKey();
KafkaMetric metric = entry.getValue();
attrs[i] = new MBeanAttributeInfo(attribute,
double.class.getName(),
metric.metricName().description(),
true,
false,
false);
i += 1;
}
return new MBeanInfo(this.getClass().getName(), "", attrs, null, null, null);
}
@Override
public Object invoke(String name, Object[] params, String[] sig) {
throw new UnsupportedOperationException("Set not allowed.");
}
@Override
public void setAttribute(Attribute attribute) {
throw new UnsupportedOperationException("Set not allowed.");
}
@Override
public AttributeList setAttributes(AttributeList list) {
throw new UnsupportedOperationException("Set not allowed.");
}
}
public static Predicate<String> compilePredicate(Map<String, ?> configs) {
String include = (String) configs.get(INCLUDE_CONFIG);
String exclude = (String) configs.get(EXCLUDE_CONFIG);
View on GitHub (pinned to c31c9215e1)
Solutions
- Remove the invoke() call from your JMX client; Kafka metric MBeans are read-only.
- If you need to change a metric/config, use the corresponding Kafka Admin client API (e.g. AlterConfigs) instead of JMX.
- If you need writable JMX attributes, register your own separate DynamicMBean outside the JmxReporter rather than reusing Kafka's metric MBeans.
Example fix
// before: jmxConnector.getMBeanServerConnection().invoke(objectName, "reset", null, null); // after: do not invoke operations on Kafka metric MBeans; read attributes only Object value = jmxConnector.getMBeanServerConnection().getAttribute(objectName, attribute);
Defensive patterns
Strategy: try-catch
Type guard
// KafkaMetricMBean is read-only; narrow to read-side only.
// isWriteAllowed = false for all attributes on this MBean.
boolean isWriteAllowed(ObjectName mbean) { return false; } Try / catch
// This MBean is registered by JmxReporter and is read-only.
// Only relevant if you script JMX writes via MBeanServer.
try {
mBeanServer.setAttribute(kafkaMetricObjectName, new Attribute(attr, val));
} catch (UnsupportedOperationException e) {
// expected: Kafka metrics MBeans are read-only; ignore or log.
} Prevention
- Treat all kafka.* JMX MBeans as read-only; never call setAttribute/invoke on them.
- If exposing JMX to external tools, document that writes are unsupported.
- Prefer JMX read-only viewers (jconsole read mode, Prometheus JMX exporter) over write-capable clients.
When it happens
Trigger: A JMX client (jconsole, JVisualVM, JMXTrans, custom JMX connector) calls MBeanServer.invoke(ObjectName, "someOperation", params, signature) on an ObjectName whose domain is the Kafka metrics prefix (e.g. "kafka.producer:type=..."). The KafkaMbean.invoke override at JmxReporter.java:282 unconditionally throws.
Common situations: Operators building a custom JMX scraper that assumes metrics MBeans expose setter/action methods (common with platform MXBeans). Tooling ported from another JMX stack that calls invoke to reset counters or clear gauges. Integration tests that drive configuration changes through JMX rather than through the Kafka Admin/Config API.
Related errors
- Error creating mbean attribute for metricName :{metricName}
- Error unregistering mbean
- Error registering mbean {mbeanName}
- Could not find attribute {name}
- JMX filter for configuration{metricsConfigPrefix}.(include/e
AI-assisted analysis of apache/kafka@c31c9215e1 (2026-08-03).
Data as JSON: /data/errors/7cbeecaf862b801a.json.
Report an issue: GitHub.