Skip to content

Commit eba7e12

Browse files
ctronjpwsutton
authored andcommitted
#370: Fix the NPE by checking for null first (#371)
Add a reproducer to verify the change works and doesn't reintroduced at a later time. Signed-off-by: Jens Reimann <jreimann@redhat.com>
1 parent c864715 commit eba7e12

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

  • org.eclipse.paho.client.mqttv3.test/src/test/java/org/eclipse/paho/client/mqttv3/test
  • org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2017 Red Hat Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat Inc - initial API and implementation
10+
*******************************************************************************/
11+
package org.eclipse.paho.client.mqttv3.test;
12+
13+
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
14+
import org.eclipse.paho.client.mqttv3.MqttException;
15+
import org.junit.Test;
16+
17+
/**
18+
* This is a reproducer for issue #370
19+
*/
20+
public class Issue370Test {
21+
@Test
22+
public void noOpenClose() throws MqttException {
23+
final MqttAsyncClient client = new MqttAsyncClient("tcp://localhost", "foo-bar");
24+
client.close();
25+
}
26+
}

org.eclipse.paho.client.mqttv3/src/main/java/org/eclipse/paho/client/mqttv3/internal/ClientState.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2009, 2016 IBM Corp.
2+
* Copyright (c) 2009, 2017 IBM Corp and others.
33
*
44
* All rights reserved. This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License v1.0
@@ -17,6 +17,7 @@
1717
* James Sutton - Ping Callback (bug 473928)
1818
* Ian Craggs - fix for NPE bug 470718
1919
* James Sutton - Automatic Reconnect & Offline Buffering
20+
* Jens Reimann - Fix issue #370
2021
*/
2122
package org.eclipse.paho.client.mqttv3.internal;
2223

@@ -1354,7 +1355,9 @@ public int getMaxInFlight(){
13541355
*/
13551356
protected void close() {
13561357
inUseMsgIds.clear();
1357-
pendingMessages.clear();
1358+
if (pendingMessages != null) {
1359+
pendingMessages.clear();
1360+
}
13581361
pendingFlows.clear();
13591362
outboundQoS2.clear();
13601363
outboundQoS1.clear();

0 commit comments

Comments
 (0)