Skip to content

Commit bf2d4ea

Browse files
milos1290Enuviel
authored andcommitted
Merge pull request #27 from Leanplum/feature/fix-null-ptr
fix(inbox): fixing null pointer exception
1 parent 53b7d00 commit bf2d4ea

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

AndroidSDK/src/com/leanplum/LeanplumInbox.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,25 @@ 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+
// Message that is null will be moved to the back of the list.
311+
LeanplumInboxMessage firstMessage = messageForId(firstMessageId);
312+
if (firstMessage == null) {
313+
return -1;
314+
}
315+
LeanplumInboxMessage secondMessage = messageForId(secondMessageId);
316+
if (secondMessage == null) {
317+
return 1;
318+
}
319+
// Message with null date will be moved to the back of the list.
320+
Date firstDate = firstMessage.getDeliveryTimestamp();
321+
if (firstDate == null) {
322+
return -1;
323+
}
324+
Date secondDate = secondMessage.getDeliveryTimestamp();
325+
if (secondDate == null) {
326+
return 1;
327+
}
312328
return firstDate.compareTo(secondDate);
313329
}
314330
});

AndroidSDK/src/com/leanplum/NewsfeedMessage.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,13 @@ public Date deliveryTimestamp() {
146146
}
147147

148148
/**
149-
* Returns the delivery timestamp of the newsfeed message.
149+
* Returns the delivery timestamp of the newsfeed message,
150+
* or null if delivery timestamp is not present.
150151
*/
151152
public Date getDeliveryTimestamp() {
153+
if (deliveryTimestamp == null) {
154+
return null;
155+
}
152156
return new Date(deliveryTimestamp);
153157
}
154158

0 commit comments

Comments
 (0)