NationalSecurityAgency/ghidra · error · IllegalArgumentException

null commentType

Error message

null commentType

What it means

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.

Source

Thrown at Ghidra/Debug/Framework-TraceModeling/src/main/java/ghidra/trace/database/listing/DBTraceCommentAdapter.java:138

	 * @param span the span that must be clear
	 */
	protected void makeWay(DBTraceCommentEntry entry, Lifespan span) {
		DBTraceUtils.makeWay(entry, span, (e, s) -> e.setLifespan(s), e -> deleteData(e));
	}

	/**
	 * Set a comment at the given address for the given lifespan
	 * 
	 * @param lifespan the lifespan
	 * @param address the address
	 * @param commentType the type of comment as in
	 *            {@link Listing#setComment(Address, CommentType, String)}
	 * @param comment the comment
	 */
	public void setComment(Lifespan lifespan, Address address, CommentType commentType,
			String comment) {
		if (commentType == null) {
			throw new IllegalArgumentException("null commentType");
		}
		String oldValue = null;
		try (LockHold hold = LockHold.lock(lock.writeLock())) {
			for (DBTraceCommentEntry entry : List.copyOf(reduce(TraceAddressSnapRangeQuery
					.intersecting(new AddressRangeImpl(address, address), lifespan)).values())) {
				if (entry.type == commentType.ordinal()) {
					if (entry.getLifespan().contains(lifespan.lmin())) {
						oldValue = entry.comment;
					}
					makeWay(entry, lifespan);
				}
			}
			if (comment != null) {
				DBTraceCommentEntry entry = put(address, lifespan, null);
				entry.set((byte) commentType.ordinal(), comment);
			}
		}
		trace.setChanged(new TraceChangeRecord<>(TraceEvents.byCommentType(commentType),

View on GitHub (pinned to d5f144c24d)

Solutions

  1. Always pass a valid CommentType: CommentType.EOL, CommentType.PLATE, CommentType.PRE, etc.
  2. Add a null-check before the call and either skip the operation or default to a sensible CommentType.
  3. Use Objects.requireNonNull(commentType, ...) at the call site for an earlier, clearer error.

Example fix

// before
adapter.setComment(lifespan, addr, type, text); // type could be null

// after
if (type != null) {
    adapter.setComment(lifespan, addr, type, text);
}
// or: Objects.requireNonNull(type, "commentType must not be null");
Defensive patterns

Strategy: validation

Validate before calling

// Validate commentType before calling setComment
if (commentType == null) {
    throw new IllegalArgumentException("commentType must not be null");
    // or: return; // silently skip
}
adapter.setComment(lifespan, address, commentType, comment);

Type guard

static boolean isValidCommentType(CommentType type) {
    return type != null;
}

// Usage: if (isValidCommentType(type)) { adapter.setComment(...); }

Try / catch

try {
    adapter.setComment(lifespan, address, commentType, comment);
} catch (IllegalArgumentException e) {
    if (e.getMessage().equals("null commentType")) {
        // Should not happen if validated — log and skip
        Msg.warn(MyClass.class, "Skipping null commentType");
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling commentAdapter.setComment(lifespan, address, null, comment) — passing null as the third argument instead of a CommentType enum value.

Common situations: 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.

Related errors


AI-assisted analysis of NationalSecurityAgency/ghidra@d5f144c24d (2026-08-14). Data as JSON: /api/errors/3574f430ef33c70a. Report an issue: GitHub.