{"record":{"id":"52f5525904d9e229","repo":"flowable/flowable-engine","slug":"comment-is-null","errorCode":null,"errorMessage":"comment is null","messagePattern":"comment is null","errorType":"validation","errorClass":"FlowableIllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/SaveCommentCmd.java","lineNumber":40,"sourceCode":"import org.flowable.engine.impl.persistence.entity.CommentEntityManager;\nimport org.flowable.engine.impl.util.CommandContextUtil;\n\n/**\n * @author Tijs Rademakers\n */\npublic class SaveCommentCmd implements Command<Void>, Serializable {\n\n    private static final long serialVersionUID = 1L;\n    protected CommentEntity comment;\n\n    public SaveCommentCmd(CommentEntity comment) {\n        this.comment = comment;\n    }\n\n    @Override\n    public Void execute(CommandContext commandContext) {\n        if (comment == null) {\n            throw new FlowableIllegalArgumentException(\"comment is null\");\n        }\n        if (comment.getId() == null) {\n            throw new FlowableIllegalArgumentException(\"comment id is null\");\n        } \n        \n        CommentEntityManager commentEntityManager = CommandContextUtil.getCommentEntityManager(commandContext);\n        \n        String eventMessage = comment.getFullMessage().replaceAll(\"\\\\s+\", \" \");\n        if (eventMessage.length() > 163) {\n            eventMessage = eventMessage.substring(0, 160) + \"...\";\n        }\n        comment.setMessage(eventMessage);\n\n        commentEntityManager.update(comment);\n\n        return null;\n    }\n}","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cmd/SaveCommentCmd.java#L22-L58","documentation":"SaveCommentCmd.execute validates the Comment passed in before persisting. Flowable throws FlowableIllegalArgumentException('comment is null') when the comment object itself is null, because there is nothing to save and the update would fail downstream. It is an argument-validation guard at the start of the command.","triggerScenarios":"Calling TaskService.saveComment(null) or executing SaveCommentCmd with a null comment reference.","commonSituations":"Comment loaded by id returned null (record deleted) and then passed to saveComment; a lookup helper returning null instead of a fresh CommentEntity.","solutions":["Ensure a non-null Comment/CommentEntity is created or fetched before calling saveComment.","Check the code path that produced the comment for a null return (e.g. createComment result ignored).","If updating an existing comment, fetch it via getComment(id) and verify non-null first."],"exampleFix":"// before\nComment comment = taskService.getComment(commentId); // may be null\ncomment.setFullMessage(\"updated\");\ntaskService.saveComment(comment);\n// after\nComment comment = taskService.getComment(commentId);\nif (comment == null) {\n    throw new IllegalStateException(\"Comment \" + commentId + \" not found\");\n}\ncomment.setFullMessage(\"updated\");\ntaskService.saveComment(comment);","handlingStrategy":"validation","validationCode":"if (comment == null) { throw new IllegalArgumentException(\"comment must be non-null before saveComment\"); }","typeGuard":"if (comment instanceof Comment && comment != null) { /* safe to save */ }","tryCatchPattern":"try {\n    taskService.saveComment(comment);\n} catch (FlowableIllegalArgumentException e) {\n    if (e.getMessage().contains(\"comment is null\")) {\n        comment = taskService.addComment(taskId, processInstanceId, message);\n    }\n}","preventionTips":["Never pass a lookup result directly to saveComment without a null check","Use createComment/addComment for new comments","Log and handle deleted-comment lookups explicitly"],"tags":["validation","null-check","comment","illegal-argument"],"backgroundTag":"null-argument","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}