Skip to content

Commit

Permalink
Fix NPE
Browse files Browse the repository at this point in the history
  • Loading branch information
caoli5288 committed Sep 27, 2018
1 parent f8d0f42 commit 2662d04
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/main/java/com/mengcraft/simpleorm/RedisWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import lombok.Cleanup;
import lombok.NonNull;
import lombok.SneakyThrows;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.BinaryJedisPubSub;
Expand All @@ -17,6 +18,7 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Function;

Expand Down Expand Up @@ -142,12 +144,23 @@ private static class MessageFilter extends BinaryJedisPubSub {

@SneakyThrows
public void onMessage(byte[] channel, byte[] message) {
Collection<Consumer<byte[]>> allconsumer = handled.get(new String(channel, "utf8"));
if (allconsumer.isEmpty()) {
Collection<Consumer<byte[]>> allConsumer = handled.get(new String(channel, StandardCharsets.UTF_8));
if (allConsumer.isEmpty()) {
return;
}

for (Consumer<byte[]> consumer : allconsumer) consumer.accept(message);
for (Consumer<byte[]> consumer : allConsumer) consumer.accept(message);
}

@Override
@SneakyThrows
public void subscribe(@NonNull byte[]... channels) {
try {
super.subscribe(channels);
} catch (NullPointerException e) {
TimeUnit.MILLISECONDS.sleep(0);
subscribe(channels);
}
}
}
}

0 comments on commit 2662d04

Please sign in to comment.