{"record":{"id":"3574f430ef33c70a","repo":"NationalSecurityAgency/ghidra","slug":"null-commenttype","errorCode":null,"errorMessage":"null commentType","messagePattern":"null commentType","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceCommentAdapter.java","lineNumber":138,"sourceCode":"\t * @param span the span that must be clear\n\t */\n\tprotected void makeWay(DBTraceCommentEntry entry, Lifespan span) {\n\t\tDBTraceUtils.makeWay(entry, span, (e, s) -> e.setLifespan(s), e -> deleteData(e));\n\t}\n\n\t/**\n\t * Set a comment at the given address for the given lifespan\n\t * \n\t * @param lifespan the lifespan\n\t * @param address the address\n\t * @param commentType the type of comment as in\n\t *            {@link Listing#setComment(Address, CommentType, String)}\n\t * @param comment the comment\n\t */\n\tpublic void setComment(Lifespan lifespan, Address address, CommentType commentType,\n\t\t\tString comment) {\n\t\tif (commentType == null) {\n\t\t\tthrow new IllegalArgumentException(\"null commentType\");\n\t\t}\n\t\tString oldValue = null;\n\t\ttry (LockHold hold = LockHold.lock(lock.writeLock())) {\n\t\t\tfor (DBTraceCommentEntry entry : List.copyOf(reduce(TraceAddressSnapRangeQuery\n\t\t\t\t\t.intersecting(new AddressRangeImpl(address, address), lifespan)).values())) {\n\t\t\t\tif (entry.type == commentType.ordinal()) {\n\t\t\t\t\tif (entry.getLifespan().contains(lifespan.lmin())) {\n\t\t\t\t\t\toldValue = entry.comment;\n\t\t\t\t\t}\n\t\t\t\t\tmakeWay(entry, lifespan);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (comment != null) {\n\t\t\t\tDBTraceCommentEntry entry = put(address, lifespan, null);\n\t\t\t\tentry.set((byte) commentType.ordinal(), comment);\n\t\t\t}\n\t\t}\n\t\ttrace.setChanged(new TraceChangeRecord<>(TraceEvents.byCommentType(commentType),","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/NationalSecurityAgency/ghidra/blob/d5f144c24d6bc53c9cbf4448c6d11143e7696206/Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceCommentAdapter.java#L120-L156","documentation":"Thrown by DBTraceCommentAdapter.setComment() when the commentType parameter is null. The method requires a valid CommentType enum (e.g., EOL, PLATE, PRE, POST, REPEATABLE) to know which comment slot to write to. A null comment type is a programming error — the adapter cannot determine where to store the comment.","triggerScenarios":"Calling commentAdapter.setComment(lifespan, address, null, comment) — passing null as the third argument instead of a CommentType enum value.","commonSituations":"Null passed from a variable that was not initialized; deserialized comment type that resolved to null; copy-paste error omitting the CommentType argument; refactoring that changed a method signature and left a null default.","solutions":["Always pass a valid CommentType: CommentType.EOL, CommentType.PLATE, CommentType.PRE, etc.","Add a null-check before the call and either skip the operation or default to a sensible CommentType.","Use Objects.requireNonNull(commentType, ...) at the call site for an earlier, clearer error."],"exampleFix":"// before\nadapter.setComment(lifespan, addr, type, text); // type could be null\n\n// after\nif (type != null) {\n    adapter.setComment(lifespan, addr, type, text);\n}\n// or: Objects.requireNonNull(type, \"commentType must not be null\");","handlingStrategy":"validation","validationCode":"// Validate commentType before calling setComment\nif (commentType == null) {\n    throw new IllegalArgumentException(\"commentType must not be null\");\n    // or: return; // silently skip\n}\nadapter.setComment(lifespan, address, commentType, comment);","typeGuard":"static boolean isValidCommentType(CommentType type) {\n    return type != null;\n}\n\n// Usage: if (isValidCommentType(type)) { adapter.setComment(...); }","tryCatchPattern":"try {\n    adapter.setComment(lifespan, address, commentType, comment);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().equals(\"null commentType\")) {\n        // Should not happen if validated — log and skip\n        Msg.warn(MyClass.class, \"Skipping null commentType\");\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always pass a non-null CommentType enum value.","Add Objects.requireNonNull(commentType) at the call site as a defensive guard.","Use static analysis or annotations (@NonNull) to catch null commentType at compile time."],"tags":["comment","null-argument","validation","trace-modeling"],"backgroundTag":null,"analyzedSha":"d5f144c24d6bc53c9cbf4448c6d11143e7696206","analyzedAt":"2026-08-14T01:00:57.564Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}