{"record":{"id":"12f43445198cc606","repo":"apache/pulsar","slug":"unexpected-monitoring-class-monclass","errorCode":null,"errorMessage":"Unexpected monitoring class: ${monClass}","messagePattern":"Unexpected monitoring class: (.+?)","errorType":"exception","errorClass":"PulsarAdminException","httpStatus":null,"severity":"error","filePath":"pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroup.java","lineNumber":435,"sourceCode":"    // Visibility for unit testing\n    protected static long getRgUsageReportedCount (String rgName, String monClassName) {\n        return (long) rgLocalUsageReportCount.labels(rgName, monClassName).get();\n    }\n\n    // Visibility for unit testing\n    protected static BytesAndMessagesCount accumulateBMCount(BytesAndMessagesCount ... bmCounts) {\n        BytesAndMessagesCount retBMCount = new BytesAndMessagesCount();\n        for (int ix = 0; ix < bmCounts.length; ix++) {\n            retBMCount.messages += bmCounts[ix].messages;\n            retBMCount.bytes += bmCounts[ix].bytes;\n        }\n        return retBMCount;\n    }\n\n    private void checkMonitoringClass(ResourceGroupMonitoringClass monClass) throws PulsarAdminException {\n        if (monClass != ResourceGroupMonitoringClass.Publish && monClass != ResourceGroupMonitoringClass.Dispatch) {\n            String errMesg = \"Unexpected monitoring class: \" + monClass;\n            throw new PulsarAdminException(errMesg);\n        }\n    }\n\n    // Fill usage about a particular monitoring class in the transport-manager callback\n    // for reporting local stats to other brokers.\n    // Returns true if something was filled.\n    // Visibility for unit testing.\n    protected boolean setUsageInMonitoredEntity(ResourceGroupMonitoringClass monClass, NetworkUsage p) {\n        long bytesUsed, messagesUsed;\n        boolean sendReport;\n        int numSuppressions = 0;\n        PerMonitoringClassFields monEntity;\n\n        final int idx = monClass.ordinal();\n        monEntity = this.monitoringClassFields[idx];\n\n        monEntity.localUsageStatsLock.lock();\n        try {","sourceCodeStart":417,"sourceCodeEnd":453,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-broker/src/main/java/org/apache/pulsar/broker/resourcegroup/ResourceGroup.java#L417-L453","documentation":"ResourceGroup.checkMonitoringClass only accepts Publish or Dispatch monitoring classes; any other ResourceGroupMonitoringClass value reaches the limit/usage accounting path and throws PulsarAdminException. This guards internal resource-group stats code from unhandled enum extensions.","triggerScenarios":"Calling getConfLimits, getLocalUsageStats (and related cumulative/report stats methods), or incrementLocalUsageStats with a monitoring class other than Publish/Dispatch.","commonSituations":"New monitoring classes added to the enum without extending ResourceGroup; plugin/extension code passing a custom monitoring class; version skew where a newer enum value from config hits an older broker.","solutions":["Only pass ResourceGroupMonitoringClass.Publish or .Dispatch to resource-group APIs.","If you added a new monitoring class, extend ResourceGroup to handle it before using it.","Upgrade/downgrade broker and client so enum values match (avoid version skew).","Inspect the config for a typo or unexpected monitoring class value."],"exampleFix":"// before\nrg.getConfLimits(ResourceGroupMonitoringClass.Storage);\n// after\nrg.getConfLimits(ResourceGroupMonitoringClass.Publish);","handlingStrategy":"type-guard","validationCode":"if (monClass != ResourceGroupMonitoringClass.Publish\n    && monClass != ResourceGroupMonitoringClass.Dispatch) {\n  throw new IllegalArgumentException(\"Unsupported monitoring class: \" + monClass);\n}","typeGuard":"boolean isSupportedMonClass(ResourceGroupMonitoringClass c) {\n  return c == ResourceGroupMonitoringClass.Publish || c == ResourceGroupMonitoringClass.Dispatch;\n}","tryCatchPattern":"try {\n  stats = rg.getLocalUsageStats(monClass);\n} catch (PulsarAdminException e) {\n  if (e.getMessage() != null && e.getMessage().startsWith(\"Unexpected monitoring class\")) {\n    log.warn(\"Falling back to Dispatch stats for unsupported class \" + monClass);\n    stats = rg.getLocalUsageStats(ResourceGroupMonitoringClass.Dispatch);\n  } else throw e;\n}","preventionTips":["Restrict resource-group calls to Publish and Dispatch monitoring classes","Switch on the enum and fail fast in default case before calling broker APIs","Keep broker and client enum versions in sync","Extend ResourceGroup when adding new monitoring classes"],"tags":["broker","resource-group","enum","validation"],"backgroundTag":"unexpected-enum-value","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}