{"record":{"id":"5f2695c073defdc2","repo":"apache/flink","slug":"queryable-state-name-already-set","errorCode":null,"errorMessage":"Queryable state name already set","messagePattern":"Queryable state name already set","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java","lineNumber":245,"sourceCode":"     * <p>If a name is set, the created state will be published for queries during runtime. The name\n     * needs to be unique per job. If there is another state instance published under the same name,\n     * the job will fail during runtime.\n     *\n     * @param queryableStateName State name for queries (unique name per job)\n     * @throws IllegalStateException If queryable state name already set\n     * @deprecated The Queryable State feature is deprecated since Flink 1.18, and will be removed\n     *     in a future Flink major version.\n     */\n    @Deprecated\n    public void setQueryable(String queryableStateName) {\n        Preconditions.checkArgument(\n                ttlConfig.getUpdateType() == StateTtlConfig.UpdateType.Disabled,\n                \"Queryable state is currently not supported with TTL\");\n        if (this.queryableStateName == null) {\n            this.queryableStateName =\n                    Preconditions.checkNotNull(queryableStateName, \"Registration name\");\n        } else {\n            throw new IllegalStateException(\"Queryable state name already set\");\n        }\n    }\n\n    /**\n     * Returns the queryable state name.\n     *\n     * @return Queryable state name or <code>null</code> if not set.\n     * @deprecated The Queryable State feature is deprecated since Flink 1.18, and will be removed\n     *     in a future Flink major version.\n     */\n    @Nullable\n    @Deprecated\n    public String getQueryableStateName() {\n        return queryableStateName;\n    }\n\n    /**\n     * Returns whether the state created from this descriptor is queryable.","sourceCodeStart":227,"sourceCodeEnd":263,"githubUrl":"https://github.com/apache/flink/blob/2f3c205e9266cb30240eb7f4fdab15cad629a70f/flink-core/src/main/java/org/apache/flink/api/common/state/StateDescriptor.java#L227-L263","documentation":"setQueryable attempts to register a queryable-state name on the descriptor, but queryableStateName is already non-null from a previous successful call. A descriptor can only carry one queryable name. The method also guards against TTL being enabled (Queryable state is not supported with TTL) before reaching this check.","triggerScenarios":"Calling setQueryable(\"name\") twice on the same StateDescriptor instance; framework or helper code that registers queryable state and the user also calls it manually; copy-paste duplication of the setQueryable line.","commonSituations":"Reusable descriptor objects passed to multiple operators where each calls setQueryable; refactoring that leaves a stray setQueryable call alongside a new one; the queryable state feature being deprecated (since 1.18) so users migrating away hit this while toggling settings.","solutions":["Guard the call with descriptor.isQueryable() (or check getQueryableStateName() == null) before invoking setQueryable.","Ensure setQueryable is called exactly once per descriptor lifecycle; remove duplicate calls.","Note the feature is deprecated since Flink 1.18 and scheduled for removal — prefer another state-query mechanism and drop setQueryable entirely."],"exampleFix":"// before\ndesc.setQueryable(\"myState\");\n...\ndesc.setQueryable(\"myState\"); // throws on second call\n\n// after\nif (!desc.isQueryable()) {\n    desc.setQueryable(\"myState\");\n}","handlingStrategy":"validation","validationCode":"if (!descriptor.isQueryable()) {\n    descriptor.setQueryable(queryableStateName);\n} else if (!descriptor.getQueryableStateName().equals(queryableStateName)) {\n    throw new IllegalStateException(\n        \"Descriptor already registered as queryable: \"\n            + descriptor.getQueryableStateName());\n}","typeGuard":"// Guard against duplicate registration\nif (descriptor.isQueryable()) {\n    // already set; skip or assert the same name\n}","tryCatchPattern":"try {\n    descriptor.setQueryable(name);\n} catch (IllegalStateException e) {\n    // already registered; ignore if same name, else surface\n    if (!name.equals(descriptor.getQueryableStateName())) throw e;\n}","preventionTips":["Call setQueryable exactly once per descriptor; centralize the call in a builder.","Check isQueryable() before calling.","Prefer alternatives to the deprecated queryable-state feature."],"tags":["state-descriptor","queryable-state","deprecated","duplicate-call"],"backgroundTag":null,"analyzedSha":"2f3c205e9266cb30240eb7f4fdab15cad629a70f","analyzedAt":"2026-08-14T08:48:24.518Z","schemaVersion":2},"datasetVersion":"2026-08-14T10:17:34.591Z"}