{"record":{"id":"2f30f340db31f224","repo":"flowable/flowable-engine","slug":"condition-script-returns-null-for","errorCode":null,"errorMessage":"condition script returns null:  for ","messagePattern":"condition script returns null:  for ","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/scripting/ScriptCondition.java","lineNumber":45,"sourceCode":"    private final String expression;\n    private final String language;\n\n    public ScriptCondition(String expression, String language) {\n        this.expression = expression;\n        this.language = language;\n    }\n\n    @Override\n    public boolean evaluate(String elementId, DelegateExecution execution) {\n        ScriptingEngines scriptingEngines = CommandContextUtil.getProcessEngineConfiguration().getScriptingEngines();\n\n        ScriptEngineRequest.Builder builder = ScriptEngineRequest.builder()\n                .script(expression)\n                .language(language)\n                .scopeContainer(execution);\n        Object result = scriptingEngines.evaluate(builder.build()).getResult();\n        if (result == null) {\n            throw new FlowableException(\"condition script returns null: \" + expression + \" for \" + execution);\n        }\n        if (!(result instanceof Boolean)) {\n            throw new FlowableException(\"condition script returns non-Boolean: \" + result + \" (\" + result.getClass().getName() + \") for \" + execution);\n        }\n        return (Boolean) result;\n    }\n\n}\n","sourceCodeStart":27,"sourceCodeEnd":54,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/scripting/ScriptCondition.java#L27-L54","documentation":"FlowableException thrown by ScriptCondition.evaluate when a condition expression script executes but its result is null. Conditional sequence flows (e.g. exclusive gateways) require a Boolean answer, so a null result makes the routing decision impossible.","triggerScenarios":"A gateway/boundary condition expression like ${language} (or a script condition with a language such as groovy/javascript) whose script evaluates to null — e.g. returning a missing variable, an empty return, or a method returning null.","commonSituations":"Referencing a process variable that is not set; script body with no explicit return statement; a helper method returning null for edge-case inputs; typo in variable name so EL resolves to null.","solutions":["Make the condition script explicitly return a boolean (e.g. return amount > 100 in groovy/js).","Check the referenced process variables exist and are non-null before the gateway, or use null-safe defaults in the expression.","Verify the condition language is correct for the expression semantics; inspect the execution object in the message to see which variables were present.","Catch FlowableException around the engine call / API invocation and log the expression for diagnosis."],"exampleFix":"// before (groovy condition, may return null)\namount\n\n// after\nreturn amount != null ? amount > 100 : false","handlingStrategy":"validation","validationCode":"Object amount = execution.getVariable(\"amount\");\nif (amount == null) {\n    execution.setVariable(\"amount\", BigDecimal.ZERO);\n}","typeGuard":null,"tryCatchPattern":"try {\n    boolean take = condition.evaluate(scriptingEngines, execution, language, expression);\n} catch (FlowableException e) {\n    log.error(\"condition '{}' failed for {}: {}\", expression, execution, e.getMessage());\n    throw e;\n}","preventionTips":["Always write conditions as explicit boolean comparisons","Initialize process variables with defaults before gateways","Test each conditional flow branch with null and edge-case variables","Avoid scripts with no return statement in conditions"],"tags":["flowable","scripting","condition","gateway"],"backgroundTag":"unexpected-api-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"}