{"record":{"id":"6126890bf3081e0a","repo":"apache/pulsar","slug":"cannot-set-resourcetypes-when-shareconfigured-ha","errorCode":null,"errorMessage":"Cannot set resourceTypes when shareConfigured() has already been called","messagePattern":"Cannot set resourceTypes when shareConfigured\\(\\) has already been called","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java","lineNumber":241,"sourceCode":"    static class OpenTelemetryResourceConfig implements ResourceConfig, OpenTelemetryConfig {\n        OpenTelemetry openTelemetry;\n\n        public OpenTelemetryResourceConfig() {\n        }\n\n        @Override\n        public OpenTelemetryConfig openTelemetry(OpenTelemetry openTelemetry) {\n            this.openTelemetry = openTelemetry;\n            return this;\n        }\n\n    }\n\n    @Override\n    public PulsarClientSharedResourcesBuilder resourceTypes(\n            PulsarClientSharedResources.SharedResource... sharedResource) {\n        if (shareConfigured) {\n            throw new IllegalStateException(\"Cannot set resourceTypes when shareConfigured() has already been called\");\n        }\n        return resourceTypes(List.of(sharedResource));\n    }\n\n    @Override\n    public PulsarClientSharedResourcesBuilder resourceTypes(\n            Collection<PulsarClientSharedResources.SharedResource> sharedResource) {\n        if (shareConfigured) {\n            throw new IllegalStateException(\"Cannot set resourceTypes when shareConfigured() has already been called\");\n        }\n        sharedResources.addAll(sharedResource);\n        return this;\n    }\n\n    @Override\n    public PulsarClientSharedResourcesBuilder shareConfigured() {\n        if (!sharedResources.isEmpty()) {\n            throw new IllegalStateException(\"Cannot use shareConfigured() when resourceTypes has already been set\");","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java#L223-L259","documentation":"PulsarClientSharedResourcesBuilder supports two mutually exclusive sharing modes: explicitly listing shared resource types via resourceTypes(...), or sharing everything via shareConfigured(). The builder tracks shareConfigured and refuses further resourceTypes(...) calls once shareConfigured() was called, to keep the mode unambiguous.","triggerScenarios":"Calling builder.shareConfigured() and then builder.resourceTypes(...) (varargs overload) on the same builder instance.","commonSituations":"Copy-pasted builder setup where shareConfigured() is called early and resourceTypes() added later; merging configuration code paths that each configure the builder; migration from 'share all' to selective sharing without removing shareConfigured().","solutions":["Remove the shareConfigured() call and list only the resource types you want via resourceTypes(...).","Reorder the fluent chain so resourceTypes(...) is called before any shareConfigured()-dependent code (though the two are mutually exclusive, so pick one).","Use a fresh builder instance for each configuration mode instead of reusing one."],"exampleFix":"// before\nbuilder.shareConfigured().resourceTypes(SharedResource.EVENT_LOOP_GROUP); // throws\n// after\nbuilder.resourceTypes(SharedResource.EVENT_LOOP_GROUP); // selective sharing","handlingStrategy":"validation","validationCode":"if (builder instanceof PulsarClientSharedResourcesBuilderImpl\n        && shareModeAlreadySet) {\n    throw new IllegalStateException(\"Choose either shareConfigured() or resourceTypes(...), not both\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    builder.shareConfigured();\n} catch (IllegalStateException e) {\n    log.warn(\"Builder already has explicit resourceTypes; skipping share-all mode\");\n}","preventionTips":["Pick one sharing mode per builder up front: either shareConfigured() or an explicit resourceTypes list.","Configure shared resources in one code path, not scattered across modules.","Use fresh builder instances per client rather than reusing configured builders.","Document the chosen sharing mode in your client configuration code."],"tags":["pulsar","client","builder","illegal-state"],"backgroundTag":"illegal-builder-state","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"}