Fix NullPointerException in AttachmentStore.retrieveAttachment

When getAttachment is called via JSON-RPC with a parameter name that
doesn't match the expected 'id' key (e.g. 'attachmentId'), the
JsonRpcNamespace returns null for ns.getString("id"). This null value
propagates to AttachmentStore.retrieveAttachment() which passes it to
new File(attachmentsPath, null), causing a NullPointerException.

Add an early null/empty check that throws a descriptive IOException
instead of an opaque NPE. This makes the error actionable for JSON-RPC
clients that send an incorrect parameter name.

Co-Authored-By: Oz <oz-agent@warp.dev>
This commit is contained in:
Marshall Æon 2026-03-25 22:05:56 -07:00
parent c94da00212
commit 6832e21b12

View File

@ -44,6 +44,9 @@ public class AttachmentStore {
}
public StreamDetails retrieveAttachment(final String id) throws IOException {
if (id == null || id.isEmpty()) {
throw new IOException("Attachment ID must not be null or empty");
}
final var attachmentFile = new File(attachmentsPath, id);
return Utils.createStreamDetailsFromFile(attachmentFile);
}