apache/pulsar · error · IllegalArgumentException
Unknown resource type:
Error message
Unknown resource type:
What it means
getOrCreateConfig maps a SharedResource to its default ResourceConfig via a switch over SharedResourceType. A resource whose type is not one of the six known types (EventLoopGroup, DnsResolver, ThreadPool, Timer, MemoryLimitController, OpenTelemetry) reaches the default branch and throws IllegalArgumentException.
Source
Thrown at pulsar-client/src/main/java/org/apache/pulsar/client/impl/PulsarClientSharedResourcesBuilderImpl.java:282
@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:
return new MemoryLimitResourceConfig();
case OpenTelemetry:
return new OpenTelemetryResourceConfig();
default:
throw new IllegalArgumentException("Unknown resource type: " + sharedResource.getType());
}
});
}
@Override
public PulsarClientSharedResourcesBuilder configureThreadPool(
PulsarClientSharedResources.SharedResource sharedResource, Consumer<ThreadPoolConfig<?>> configurer) {
if (sharedResource.getType() != PulsarClientSharedResources.SharedResourceType.ThreadPool) {
throw new IllegalArgumentException("The shared resource " + sharedResource + " doesn't support thread pool"
+ " configuration");
}
configurer.accept(getOrCreateConfig(sharedResource));
return this;
}
@Override
public PulsarClientSharedResourcesBuilder configureEventLoop(Consumer<EventLoopGroupConfig> configurer) {
configurer.accept(getOrCreateConfig(PulsarClientSharedResources.SharedResource.EventLoopGroup));View on GitHub (pinned to 820761864e)
Solutions
- Use only the built-in SharedResource constants/types from the same Pulsar version as the client library (check PulsarClientSharedResources.SharedResourceType).
- Align all Pulsar client jar versions on the classpath; duplicate shaded/unshaded jars cause enum mismatch.
- Verify with a debug print that sharedResource.getType() is a known SharedResourceType before calling the configure method.
- Upgrade the client library if the resource type is a newer addition not present in your current version.
Example fix
// before SharedResource custom = SharedResource.of(myCustomType, "mine"); // custom type builder.configureThreadPool(custom, cfg -> ...); // throws Unknown resource type // after builder.configureThreadPool(PulsarClientSharedResources.THREAD_POOL, cfg -> ...);
Defensive patterns
Strategy: validation
Validate before calling
PulsarClientSharedResources.SharedResourceType t = resource.getType();
boolean known = t == SharedResourceType.EventLoopGroup || t == SharedResourceType.DnsResolver
|| t == SharedResourceType.ThreadPool || t == SharedResourceType.Timer
|| t == SharedResourceType.MemoryLimitController || t == SharedResourceType.OpenTelemetry;
if (!known) throw new IllegalArgumentException("Unsupported shared resource type: " + t); Type guard
static boolean isKnownResourceType(PulsarClientSharedResources.SharedResource r) {
switch (r.getType()) {
case EventLoopGroup: case DnsResolver: case ThreadPool:
case Timer: case MemoryLimitController: case OpenTelemetry:
return true;
default:
return false;
}
} Try / catch
try {
builder.configureEventLoop(cfg -> cfg.numThreads(8));
} catch (IllegalArgumentException e) {
if (e.getMessage().startsWith("Unknown resource type")) {
log.error("SharedResource type not supported by this client version: {}", e.getMessage());
} else { throw e; }
} Prevention
- Only use SharedResource constants shipped with the same Pulsar client version you compile against.
- Check for duplicate/shaded pulsar-client jars on the classpath that could shadow enum values.
- When upgrading, diff SharedResourceType enums between versions before feeding resources to configure* methods.
- Never define custom SharedResourceType values; the builder switch cannot handle them.
When it happens
Trigger: Passing a SharedResource with a custom or unrecognized SharedResourceType to any configure* method (configureThreadPool, configureEventLoop, configureDnsResolver, configureTimer, configureMemoryLimitController, configureOpenTelemetry), typically because a SharedResource from a newer Pulsar version or a user-defined type is fed to an older builder.
Common situations: Upgrading/downgrading Pulsar client so a SharedResourceType enum constant exists in one jar but not the other; constructing a SharedResource with a hand-rolled type instead of using the provided constants; mixing client versions on the classpath (shaded vs non-shaded jars).
Related errors
- ResourceGroupCreate: Invalid null ResourceGroup config
- ResourceGroupCreate: can't create resource group with an emp
- Invalid key-shared mode: ${keySharedMode}
- Invalid key-shared mode: ${keySharedMode}
- Invalid auto split/merge configuration: ${message}
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/a7993ee96ba03521.
Report an issue: GitHub.