{"record":{"id":"3c6db678ad87741f","repo":"apache/beam","slug":"unable-to-construct-s-counter-for-ptransform-id-s-name-s","errorCode":null,"errorMessage":"Unable to construct %s counter for PTransform {id=%s, name=%s}","messagePattern":"Unable to construct (.+?) counter for PTransform (.+?)","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/harness/src/main/java/org/apache/beam/fn/harness/data/PTransformFunctionRegistry.java","lineNumber":103,"sourceCode":"    this.stateTracker = stateTracker;\n  }\n\n  /**\n   * Register the runnable to process the specific pTransformId and track its execution time.\n   *\n   * @param pTransformId\n   * @param pTransformUniqueName\n   * @param runnable\n   */\n  public void register(\n      String pTransformId, String pTransformUniqueName, ThrowingRunnable runnable) {\n    SimpleMonitoringInfoBuilder miBuilder = new SimpleMonitoringInfoBuilder();\n    miBuilder.setUrn(executionStateUrn);\n    miBuilder.setType(MonitoringInfoConstants.TypeUrns.SUM_INT64_TYPE);\n    miBuilder.setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, pTransformId);\n    MonitoringInfo mi = miBuilder.build();\n    if (mi == null) {\n      throw new IllegalStateException(\n          String.format(\n              \"Unable to construct %s counter for PTransform {id=%s, name=%s}\",\n              executionStateUrn, pTransformId, pTransformUniqueName));\n    }\n    String shortId = shortIds.getOrCreateShortId(mi);\n    ExecutionState executionState =\n        stateTracker.create(shortId, pTransformId, pTransformUniqueName, stateName);\n\n    ThrowingRunnable wrapped =\n        () -> {\n          try (ExecutionState.ActiveState ignored = executionState.scopedActivate()) {\n            runnable.run();\n          }\n        };\n    runnables.add(wrapped);\n  }\n\n  /**","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/harness/src/main/java/org/apache/beam/fn/harness/data/PTransformFunctionRegistry.java#L85-L121","documentation":"After building a MonitoringInfo for the execution state (URN + SUM_INT64 type + PTRANSFORM label), SimpleMonitoringInfoBuilder.build() returned null, indicating the monitoring info was incomplete/invalid (e.g. the URN is not recognized as a valid execution state counter). The registry throws IllegalStateException naming the URN and PTransform it could not instrument.","triggerScenarios":"register(...) is called with an executionStateUrn that SimpleMonitoringInfoBuilder cannot turn into a valid counter — commonly because the URN is empty or not a valid execution-state URN, so miBuilder.build() yields null.","commonSituations":"Custom runner passes an unsupported/wrong URN string; constants changed across Beam versions; URN left null during registry construction in tests.","solutions":["Ensure the executionStateUrn passed to register() is a valid execution-state Urns constant and non-null.","Log/inspect the constructed MonitoringInfo (miBuilder) to see which validation failed.","Update URN constants after Beam SDK upgrades.","Add a unit test exercising register() with the URNs used by your runner."],"exampleFix":"// before\nregistry.register(pTransformId, pTransformName, fn, \"process_bad_urn\");\n// after\nregistry.register(pTransformId, pTransformName, fn, MonitoringInfoConstants.Urns.PROCESS_BUNDLE_MSECS);","handlingStrategy":"validation","validationCode":"SimpleMonitoringInfoBuilder b = new SimpleMonitoringInfoBuilder(); b.setUrn(urn); b.setType(MonitoringInfoConstants.TypeUrns.SUM_INT64_TYPE); b.setLabel(MonitoringInfoConstants.Labels.PTRANSFORM, id); if (b.build() == null) throw new IllegalStateException(\"URN not constructible: \" + urn);","typeGuard":null,"tryCatchPattern":"try { registry.register(id, name, fn, urn); } catch (IllegalStateException e) { LOG.error(\"Counter construction failed for {}\", urn, e); throw e; }","preventionTips":["Pre-validate MonitoringInfo construction with the same builder","Use non-null, valid Urns constants","Add tests covering register() with your URNs"],"tags":["apache-beam","java-harness","metrics","monitoring-info"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}