{"record":{"id":"2b1341c2d1ef3d64","repo":"flowable/flowable-engine","slug":"error-code-must-not-be-null-2b1341","errorCode":null,"errorMessage":"Error Code must not be null.","messagePattern":"Error Code must not be null\\.","errorType":"validation","errorClass":"ActivitiIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/delegate/BpmnError.java","lineNumber":49,"sourceCode":"public class BpmnError extends ActivitiException {\n\n    private static final long serialVersionUID = 1L;\n\n    private String errorCode;\n\n    public BpmnError(String errorCode) {\n        super(\"\");\n        setErrorCode(errorCode);\n    }\n\n    public BpmnError(String errorCode, String message) {\n        super(message + \" (errorCode='\" + errorCode + \"')\");\n        setErrorCode(errorCode);\n    }\n\n    protected void setErrorCode(String errorCode) {\n        if (errorCode == null) {\n            throw new ActivitiIllegalArgumentException(\"Error Code must not be null.\");\n        }\n        if (errorCode.length() < 1) {\n            throw new ActivitiIllegalArgumentException(\"Error Code must not be empty.\");\n        }\n        this.errorCode = errorCode;\n    }\n\n    public String getErrorCode() {\n        return errorCode;\n    }\n\n    @Override\n    public String toString() {\n        return super.toString() + \" (errorCode='\" + errorCode + \"')\";\n    }\n\n}\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/delegate/BpmnError.java#L31-L67","documentation":"BpmnError requires an errorCode string used to match BPMN error boundary events. The protected setErrorCode() method rejects a null errorCode with ActivitiIllegalArgumentException. Any BpmnError constructor that receives null propagates this error, so an error event can never be thrown or matched without a code.","triggerScenarios":"new BpmnError(null) or new BpmnError(message, null) — any constructor path that calls setErrorCode with a null value, e.g. passing a null variable holding the business error code.","commonSituations":"Java delegates or task listeners throwing BpmnError with an error code fetched from process variables or external data that turned out to be null; refactors where a constant became a nullable lookup.","solutions":["Ensure the error code passed to new BpmnError(code) is a non-null string literal or resolved variable.","Add a null check / default before throwing: throw new BpmnError(code != null ? code : \"DEFAULT_ERROR\").","Trace where the code originates (process variable, service response) and fix the null source."],"exampleFix":"// before\nString code = (String) execution.getVariable(\"errCode\");\nthrow new BpmnError(code); // NPE-ish: ActivitiIllegalArgumentException\n// after\nString code = (String) execution.getVariable(\"errCode\");\nif (code == null) { code = \"ORDER_ERROR\"; }\nthrow new BpmnError(code);","handlingStrategy":"validation","validationCode":"if (errorCode == null) throw new IllegalArgumentException(\"errorCode required before throwing BpmnError\");","typeGuard":"boolean isValidErrorCode(String s) { return s != null; }","tryCatchPattern":"try { throwOrPropagate(); } catch (ActivitiIllegalArgumentException e) { logger.error(\"BpmnError built with null errorCode\", e); throw new BpmnError(\"DEFAULT_ERROR\"); }","preventionTips":["Centralize BpmnError creation in a helper that enforces a non-null code","Null-check process variables before feeding them into error codes","Wrap throwBpmnError logic in one utility per process"],"tags":["bpmn","null-argument","validation","error-handling"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}