apache/pulsar · error · UnsupportedOperationException
Component cannot get state store
Error message
Component cannot get state store
What it means
BaseContext.getStateStore(name) is a default interface method that deliberately throws UnsupportedOperationException. Only components whose runtime actually provides a StateStoreServiceProvider (e.g. Java functions with the state store wired) can return a store; other components cannot.
Source
Thrown at pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/BaseContext.java:90
* Get the secret associated with this key.
*
* @param secretName The name of the secret
* @return The secret if anything was found or null
*/
String getSecret(String secretName);
/**
* Get the state store with the provided store name in the tenant & namespace.
*
* @param name the state store name
* @param <X> the type of interface of the store to return
* @return the state store instance.
*
* @throws ClassCastException if the return type isn't a type
* or interface of the actual returned store.
*/
default <X extends StateStore> X getStateStore(String name) {
throw new UnsupportedOperationException("Component cannot get state store");
}
/**
* Get the state store with the provided store name.
*
* @param tenant the state tenant name
* @param ns the state namespace name
* @param name the state store name
* @param <X> the type of interface of the store to return
* @return the state store instance.
*
* @throws ClassCastException if the return type isn't a type
* or interface of the actual returned store.
*/
default <X extends StateStore> X getStateStore(String tenant, String ns, String name) {
throw new UnsupportedOperationException("Component cannot get state store");
}
View on GitHub (pinned to 820761864e)
Solutions
- Ensure the function runs where a state store provider is configured (built-in Java function context)
- Wrap the call in try-catch for UnsupportedOperationException and degrade gracefully
- Use the Pulsar Client API to read state directly if the store is unavailable in this component
- Check the runtime/container has state storage enabled (stateful functions config)
Example fix
// before
StateStore store = context.getStateStore("mystore"); // throws
// after
try {
StateStore store = context.getStateStore("mystore");
} catch (UnsupportedOperationException e) {
// state store not supported by this component; use fallback
} Defensive patterns
Strategy: try-catch
Validate before calling
// No pre-check API exists; capability must be discovered by calling. // Guard deployment config instead: confirm state storage is enabled.
Try / catch
try {
StateStore store = ctx.getStateStore("mystore");
} catch (UnsupportedOperationException e) {
// fallback: no state store in this component
} Prevention
- Only rely on state stores in Java functions with state enabled
- Design sink/connector code to tolerate missing state support
- Document state store requirements in deployment configs
When it happens
Trigger: Calling context.getStateStore("storeName") from a context whose implementation does not override getStateStore — e.g. an IO connector (source/sink) context or an older/custom Context implementation without state store support.
Common situations: Using the same function code in a sink where state stores are not wired, running on a deployment without the state (BookKeeper table service) service enabled, or a custom Context implementation.
Related errors
- not implemented
- Not implemented
- Expire message by timestamp is not supported for non-persist
- Expire message by position is not supported for non-persiste
- PublishTxnMessage is not supported by non-persistent topic
AI-assisted analysis of apache/pulsar@820761864e (2026-09-06).
Data as JSON: /api/errors/6021dbe9ec9c199c.
Report an issue: GitHub.