Skip to content

Commit b38bf15

Browse files
committed
Interrupt exceptions should not lead to NPEs. Fixes #16.
1 parent 4e6318f commit b38bf15

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

src/main/java/com/github/brainlag/nsq/Connection.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public Connection(final ServerAddress serverAddress, final NSQConfig config) thr
6868
final NSQCommand ident = NSQCommand.instance("IDENTIFY", config.toString().getBytes());
6969
try {
7070
final NSQFrame response = commandAndWait(ident);
71-
LogManager.getLogger(this).info("Server identification: " + ((ResponseFrame) response).getMessage());
71+
if (response != null) {
72+
LogManager.getLogger(this).info("Server identification: " + ((ResponseFrame) response).getMessage());
73+
}
7274
} catch (final TimeoutException e) {
7375
LogManager.getLogger(this).error("Creating connection timed out", e);
7476
close();

src/main/java/com/github/brainlag/nsq/NSQConsumer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void cleanClose() {
153153
try {
154154
for (final Connection connection : connections.values()) {
155155
final NSQFrame frame = connection.commandAndWait(command);
156-
if (frame instanceof ErrorFrame) {
156+
if (frame != null && frame instanceof ErrorFrame) {
157157
final String err = ((ErrorFrame) frame).getErrorMessage();
158158
if (err.startsWith("E_INVALID")) {
159159
throw new IllegalStateException(err);

src/main/java/com/github/brainlag/nsq/NSQProducer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public void produceMulti(String topic, List<byte[]> messages) throws TimeoutExce
9090

9191

9292
NSQFrame frame = c.commandAndWait(command);
93-
if (frame instanceof ErrorFrame) {
93+
if (frame != null && frame instanceof ErrorFrame) {
9494
String err = ((ErrorFrame) frame).getErrorMessage();
9595
if (err.startsWith("E_BAD_TOPIC")) {
9696
throw new BadTopicException(err);
@@ -112,7 +112,7 @@ public void produce(String topic, byte[] message) throws NSQException, TimeoutEx
112112
try {
113113
NSQCommand command = NSQCommand.instance("PUB " + topic, message);
114114
NSQFrame frame = c.commandAndWait(command);
115-
if (frame instanceof ErrorFrame) {
115+
if (frame != null && frame instanceof ErrorFrame) {
116116
String err = ((ErrorFrame) frame).getErrorMessage();
117117
if (err.startsWith("E_BAD_TOPIC")) {
118118
throw new BadTopicException(err);

0 commit comments

Comments
 (0)