Skip to content

Commit 8032bde

Browse files
Fix NullPointerException in IterableInAppManager.syncWithRemoteQueue
Add null safety checks to prevent NPE caused by race conditions where messages may be null or removed from storage between check and access. Consolidates the duplicate storage lookup into a single call and adds null guards when iterating both remote and local message queues. Fixes #485 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent c42e6bc commit 8032bde

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -339,20 +339,20 @@ private void syncWithRemoteQueue(List<IterableInAppMessage> remoteQueue) {
339339
Map<String, IterableInAppMessage> remoteQueueMap = new HashMap<>();
340340

341341
for (IterableInAppMessage message : remoteQueue) {
342+
if (message == null) {
343+
continue;
344+
}
345+
342346
remoteQueueMap.put(message.getMessageId(), message);
343347

344-
boolean isInAppStored = storage.getMessage(message.getMessageId()) != null;
348+
IterableInAppMessage localMessage = storage.getMessage(message.getMessageId());
345349

346-
if (!isInAppStored) {
350+
if (localMessage == null) {
347351
storage.addMessage(message);
348352
onMessageAdded(message);
349353

350354
changed = true;
351-
}
352-
353-
if (isInAppStored) {
354-
IterableInAppMessage localMessage = storage.getMessage(message.getMessageId());
355-
355+
} else {
356356
boolean shouldOverwriteInApp = !localMessage.isRead() && message.isRead();
357357

358358
if (shouldOverwriteInApp) {
@@ -363,7 +363,11 @@ private void syncWithRemoteQueue(List<IterableInAppMessage> remoteQueue) {
363363
}
364364
}
365365

366-
for (IterableInAppMessage localMessage : storage.getMessages()) {
366+
List<IterableInAppMessage> localMessages = storage.getMessages();
367+
for (IterableInAppMessage localMessage : localMessages) {
368+
if (localMessage == null) {
369+
continue;
370+
}
367371
if (!remoteQueueMap.containsKey(localMessage.getMessageId())) {
368372
storage.removeMessage(localMessage);
369373

0 commit comments

Comments
 (0)