{"record":{"id":"9c6d517bef07aa68","repo":"flowable/flowable-engine","slug":"query-return-results-size-results-instea-9c6d51","errorCode":null,"errorMessage":"Query return \" + results.size() + \" results instead of max 1","messagePattern":"Query return \" \\+ results\\.size\\(\\) \\+ \" results instead of max 1","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/query/AbstractQuery.java","lineNumber":191,"sourceCode":"            return executeList(commandContext);\n        } else {\n            return executeCount(commandContext);\n        }\n    }\n\n    public abstract long executeCount(CommandContext commandContext);\n\n    /**\n     * Executes the actual query to retrieve the list of results.\n     */\n    public abstract List<U> executeList(CommandContext commandContext);\n\n    public U executeSingleResult(CommandContext commandContext) {\n        List<U> results = executeList(commandContext);\n        if (results.size() == 1) {\n            return results.get(0);\n        } else if (results.size() > 1) {\n            throw new FlowableException(\"Query return \" + results.size() + \" results instead of max 1\");\n        }\n        return null;\n    }\n\n}\n","sourceCodeStart":173,"sourceCodeEnd":197,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine-common/src/main/java/org/flowable/common/engine/impl/query/AbstractQuery.java#L173-L197","documentation":"Result-shape guard in AbstractQuery.executeSingleResult: singleResult() was called but the query matched more than one entity (count in message); the query's filters are too broad for a single-result expectation.","triggerScenarios":"Calling e.g. taskQuery().processInstanceId(pid).singleResult() when several tasks/executions/variables match the filter — i.e. the query criteria are not unique.","commonSituations":"Assuming processInstanceId returns exactly one execution when there are concurrent child executions; filters that match historical duplicates; missing unique constraint in custom data.","solutions":["Tighten the query filters (id, key) so exactly one row matches","Use list() when multiple results are legitimate"],"exampleFix":"// before\nExecution e = runtimeService.createExecutionQuery()\n    .processInstanceId(pid).singleResult();\n// after\nExecution e = runtimeService.createExecutionQuery()\n    .processInstanceId(pid).processDefinitionKey(key).singleResult();","handlingStrategy":"validation","validationCode":"long matches = runtimeService.createExecutionQuery()\n    .processInstanceId(pid).count();\nif (matches > 1) {\n    throw new IllegalStateException(\"criteria not unique: \" + matches);\n}","typeGuard":null,"tryCatchPattern":"try {\n    return query.singleResult();\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"instead of max 1\")) {\n        return query.list().get(0);\n    }\n    throw e;\n}","preventionTips":["Verify filter uniqueness (count() before singleResult())","Add active()/unique criteria to narrow results","Use .list() when duplicates are expected"],"tags":["query","multiple-results","single-result"],"backgroundTag":"unexpected-response-shape","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-18T11:17:12.947Z"}