Skip to content

Commit 8c24345

Browse files
committed
fix(inbox): fixing null pointer exception
1 parent 038619b commit 8c24345

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

AndroidSDK/src/com/leanplum/LeanplumInbox.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,18 @@ public List<String> messagesIds() {
306306
try {
307307
Collections.sort(messageIds, new Comparator<String>() {
308308
@Override
309-
public int compare(String firstMessage, String secondMessage) {
310-
Date firstDate = messageForId(firstMessage).getDeliveryTimestamp();
311-
Date secondDate = messageForId(secondMessage).getDeliveryTimestamp();
309+
public int compare(String firstMessageId, String secondMessageId) {
310+
LeanplumInboxMessage firstMessage = messageForId(firstMessageId);
311+
LeanplumInboxMessage secondMessage = messageForId(secondMessageId);
312+
// Message that is null will be moved to the back of the list.
313+
if (firstMessage == null) {
314+
return -1;
315+
}
316+
if (secondMessage == null) {
317+
return 1;
318+
}
319+
Date firstDate = firstMessage.getDeliveryTimestamp();
320+
Date secondDate = secondMessage.getDeliveryTimestamp();
312321
return firstDate.compareTo(secondDate);
313322
}
314323
});

AndroidSDK/src/com/leanplum/NewsfeedMessage.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ public Date deliveryTimestamp() {
149149
* Returns the delivery timestamp of the newsfeed message.
150150
*/
151151
public Date getDeliveryTimestamp() {
152+
if (deliveryTimestamp == null) {
153+
return new Date();
154+
}
152155
return new Date(deliveryTimestamp);
153156
}
154157

0 commit comments

Comments
 (0)