apache/pulsar · error · IllegalStateException
Cannot use shareConfigured() when resourceTypes has already
Error message
Cannot use shareConfigured() when resourceTypes has already been set
What it means
The inverse guard of the resourceTypes checks: shareConfigured() (share-everything mode) cannot be used once specific resource types were already registered, since the builder cannot represent both an exclusive list and share-all mode at once.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java:259
throw new IllegalStateException("Cannot set resourceTypes when shareConfigured() has already been called");
}
return resourceTypes(List.of(sharedResource));
}
@Override
public PulsarClientSharedResourcesBuilder resourceTypes(
Collection<PulsarClientSharedResources.SharedResource> sharedResource) {
if (shareConfigured) {
throw new IllegalStateException("Cannot set resourceTypes when shareConfigured() has already been called");
}
sharedResources.addAll(sharedResource);
return this;
}
@Override
public PulsarClientSharedResourcesBuilder shareConfigured() {
if (!sharedResources.isEmpty()) {
throw new IllegalStateException("Cannot use shareConfigured() when resourceTypes has already been set");
}
shareConfigured = true;
return this;
}
@SuppressWarnings("unchecked")
private <T extends ResourceConfig> T getOrCreateConfig(PulsarClientSharedResources.SharedResource sharedResource) {
return (T) resourceConfigs.computeIfAbsent(sharedResource, k -> {
switch (sharedResource.getType()) {
case EventLoopGroup:
return new EventLoopResourceConfig();
case DnsResolver:
return new DnsResolverResourceConfig();
case ThreadPool:
return new ThreadPoolResourceConfig();
case Timer:
return new TimerResourceConfig();
case MemoryLimitController:View on GitHub (pinned to 820761864e)
Solutions
- Remove the shareConfigured() call when you are explicitly listing resourceTypes; the listed types already define what is shared.
- Call shareConfigured() before any resourceTypes(...) call if share-all mode is intended, and skip resourceTypes entirely.
- Use a new builder instance if the two configurations must coexist for different clients.
Example fix
// before builder.resourceTypes(SharedResource.EVENT_LOOP_GROUP).shareConfigured(); // throws // after builder.resourceTypes(SharedResource.EVENT_LOOP_GROUP); // explicit list only
Defensive patterns
Strategy: validation
Validate before calling
if (!resourcesToShare.isEmpty()) {
builder.resourceTypes(resourcesToShare); // do not also call shareConfigured()
} else {
builder.shareConfigured();
} Try / catch
try {
builder.shareConfigured();
} catch (IllegalStateException e) {
log.warn("resourceTypes already set; explicit list wins, skipping share-all");
} Prevention
- Treat shareConfigured() as an alternative to resourceTypes, never a complement.
- Build the resource list first; only fall back to shareConfigured() when the list is empty.
- Keep builder construction in one factory method with a single mode branch.
- Add a unit test asserting the builder chain you ship does not throw IllegalStateException.
When it happens
Trigger: Calling builder.resourceTypes(...) (either overload) and then builder.shareConfigured() on the same builder instance.
Common situations: Fluent chains that append shareConfigured() 'for good measure' after listing resources; merged configuration from two code modules each adding resources then finalizing with shareConfigured(); framework code that always finalizes with shareConfigured().
Related errors
- Cannot set resourceTypes when shareConfigured() has already
- Try to reserve/release memory failed, the param memorySize i
- Failed to decode message from topic ${topic} with schemaId $
- The schema is not a KeyValueSchema
- Pulsar client has been closed, can not build LookupService w
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/70f56df14c585ea5.
Report an issue: GitHub.