From 6832e21b12c564d5f4c0ee271c5f0e8b60a54ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marshall=20=C3=86on?= Date: Wed, 25 Mar 2026 22:05:56 -0700 Subject: [PATCH] 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 --- .../java/org/asamk/signal/manager/storage/AttachmentStore.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/src/main/java/org/asamk/signal/manager/storage/AttachmentStore.java b/lib/src/main/java/org/asamk/signal/manager/storage/AttachmentStore.java index d25f1a72..c9b8843f 100644 --- a/lib/src/main/java/org/asamk/signal/manager/storage/AttachmentStore.java +++ b/lib/src/main/java/org/asamk/signal/manager/storage/AttachmentStore.java @@ -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); }