{"record":{"id":"6021dbe9ec9c199c","repo":"apache/pulsar","slug":"component-cannot-get-state-store","errorCode":null,"errorMessage":"Component cannot get state store","messagePattern":"Component cannot get state store","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/BaseContext.java","lineNumber":90,"sourceCode":"     * Get the secret associated with this key.\n     *\n     * @param secretName The name of the secret\n     * @return The secret if anything was found or null\n     */\n    String getSecret(String secretName);\n\n    /**\n     * Get the state store with the provided store name in the tenant & namespace.\n     *\n     * @param name the state store name\n     * @param <X> the type of interface of the store to return\n     * @return the state store instance.\n     *\n     * @throws ClassCastException if the return type isn't a type\n     * or interface of the actual returned store.\n     */\n    default <X extends StateStore> X getStateStore(String name) {\n        throw new UnsupportedOperationException(\"Component cannot get state store\");\n    }\n\n    /**\n     * Get the state store with the provided store name.\n     *\n     * @param tenant the state tenant name\n     * @param ns the state namespace name\n     * @param name the state store name\n     * @param <X> the type of interface of the store to return\n     * @return the state store instance.\n     *\n     * @throws ClassCastException if the return type isn't a type\n     * or interface of the actual returned store.\n     */\n    default <X extends StateStore> X getStateStore(String tenant, String ns, String name) {\n        throw new UnsupportedOperationException(\"Component cannot get state store\");\n    }\n","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/BaseContext.java#L72-L108","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"// before\nStateStore store = context.getStateStore(\"mystore\"); // throws\n// after\ntry {\n    StateStore store = context.getStateStore(\"mystore\");\n} catch (UnsupportedOperationException e) {\n    // state store not supported by this component; use fallback\n}","handlingStrategy":"try-catch","validationCode":"// No pre-check API exists; capability must be discovered by calling.\n// Guard deployment config instead: confirm state storage is enabled.","typeGuard":null,"tryCatchPattern":"try {\n    StateStore store = ctx.getStateStore(\"mystore\");\n} catch (UnsupportedOperationException e) {\n    // fallback: no state store in this component\n}","preventionTips":["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"],"tags":["java","pulsar-functions","state-store","unsupported-operation"],"backgroundTag":"operation-not-supported","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}