Skip to content

Commit 78fd1cc

Browse files
authored
Merge pull request #184 from scottyab/feature/fix-nullpointer
NPE fix when iterating through ids in the SubscriptionSuccessfulMessage
2 parents 9b031cf + 16bd0a0 commit 78fd1cc

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/main/java/com/pusher/client/channel/impl/PresenceChannelImpl.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
package com.pusher.client.channel.impl;
22

3-
import java.util.Collections;
4-
import java.util.LinkedHashMap;
5-
import java.util.LinkedHashSet;
6-
import java.util.List;
7-
import java.util.Map;
8-
import java.util.Set;
9-
103
import com.google.gson.Gson;
114
import com.google.gson.annotations.SerializedName;
12-
135
import com.pusher.client.AuthorizationFailureException;
146
import com.pusher.client.Authorizer;
157
import com.pusher.client.channel.ChannelEventListener;
@@ -20,6 +12,13 @@
2012
import com.pusher.client.connection.impl.InternalConnection;
2113
import com.pusher.client.util.Factory;
2214

15+
import java.util.Collections;
16+
import java.util.LinkedHashMap;
17+
import java.util.LinkedHashSet;
18+
import java.util.List;
19+
import java.util.Map;
20+
import java.util.Set;
21+
2322
public class PresenceChannelImpl extends PrivateChannelImpl implements PresenceChannel {
2423

2524
private static final String MEMBER_ADDED_EVENT = "pusher_internal:member_added";
@@ -126,13 +125,14 @@ private void handleSubscriptionSuccessfulMessage(final String message) {
126125
final List<String> ids = presenceData.ids;
127126
final Map<String, Object> hash = presenceData.hash;
128127

129-
// build the collection of Users
130-
for (final String id : ids) {
131-
final String userData = hash.get(id) != null ? GSON.toJson(hash.get(id)) : null;
132-
final User user = new User(id, userData);
133-
idToUserMap.put(id, user);
128+
if (ids != null && !ids.isEmpty()) {
129+
// build the collection of Users
130+
for (final String id : ids) {
131+
final String userData = hash.get(id) != null ? GSON.toJson(hash.get(id)) : null;
132+
final User user = new User(id, userData);
133+
idToUserMap.put(id, user);
134+
}
134135
}
135-
136136
final ChannelEventListener listener = getEventListener();
137137
if (listener != null) {
138138
final PresenceChannelEventListener presenceListener = (PresenceChannelEventListener)listener;

0 commit comments

Comments
 (0)