eclipse-paho / eclipse-paho/paho.mqtt.java

MQTTv5 NPE at ClientState.send during MqttClient.publish to VerneMQ server

Open
#787 6 comments 0 reactions 1 assignee Claimed by @rdasgupt View on GitHub
bug
Dominant language
Java
Stars
2.3k
Forks
919
PR merge metrics
No merged PRs in 30d

Description

- [*] Bug exists in MQTTv5 Client on Snapshot Version 1.2.3-SNAPSHOT (Develop Branch)

I am using the MQTTv5 Client connecting to a VerneMQ server.
Connecting work ok, subscribing to a topic work ok, however
I am hitting a NPE when i try to publish to a topic using the MQTTv5 client.

Similar code work fine using the v3 client.

Reproducer:
```

import java.security.NoSuchAlgorithmException;
import javax.net.ssl.*;
import org.eclipse.paho.mqttv5.client.persist.MemoryPersistence;
import org.eclipse.paho.mqttv5.client.IMqttDeliveryToken;
import org.eclipse.paho.mqttv5.client.IMqttToken;
import org.eclipse.paho.mqttv5.client.MqttCallback;
import org.eclipse.paho.mqttv5.client.MqttClient;
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
import org.eclipse.paho.mqttv5.client.MqttDisconnectResponse;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;
import org.eclipse.paho.mqttv5.common.MqttSubscription;
import org.eclipse.paho.mqttv5.common.packet.MqttProperties;

public class Reproducer {

public static void main(String args[]) throws MqttException, NoSuchAlgorithmException {
MemoryPersistence persistence = new MemoryPersistence();

SSLContext sslContext;
sslContext = SSLContext.getDefault();

MqttConnectionOptions options = new MqttConnectionOptions();
options.setSocketFactory(sslContext.getSocketFactory());
options.setCleanStart(false);
options.setUserName("testUnit123");
options.setPassword("123".getBytes());
MqttClient client = new MqttClient("ssl://sto1-k8s-clstr01-mqtt.publicdns.zone:8888", "foobar b8:27:EB:58:DF:F2", persistence);

client.connect(options);

client.setCallback(new MqttCallback() {
@Override
public void disconnected(MqttDisconnectResponse arg0) {
}

@Override
public void mqttErrorOccurred(MqttException arg0) {
}

@Override
public void messageArrived(String arg0, MqttMessage arg1) throws Exception {
}

@Override
public void deliveryComplete(IMqttDeliveryToken arg0) {
}

@Override
public void connectComplete(boolean arg0, String arg1) {
}

@Override
public void authPacketArrived(int arg0, MqttProperties arg1) {
}
});

MqttSubscription subscriptionTopic = new MqttSubscription("/acl");
MqttSubscription[] subscriptionTopics = {subscriptionTopic};
IMqttToken token = client.subscribe(subscriptionTopics);
token.waitForCompletion();

MqttMessage message = new MqttMessage("{\"units\": [{ \"id\": \"test_instrument\", \"type\": \"fhir\" }, { \"id\": \"Prov-id skrivare testUnit123 \", \"type\": \"labeler\" }, { \"id\": \"connection_test\", \"type\": \"ping\" }]}".getBytes());
message.setQos(2);
client.publish("/config", message);

while (true) {

}
}
}

```

```
Exception in thread "main" java.lang.NullPointerException
at org.eclipse.paho.mqttv5.client.internal.ClientState.send(ClientState.java:516)
at org.eclipse.paho.mqttv5.client.internal.ClientComms.internalSend(ClientComms.java:156)
at org.eclipse.paho.mqttv5.client.internal.ClientComms.sendNoWait(ClientComms.java:216)
at org.eclipse.paho.mqttv5.client.MqttAsyncClient.publish(MqttAsyncClient.java:1514)
at org.eclipse.paho.mqttv5.client.MqttClient.publish(MqttClient.java:564)
at Reproducer.main(Reproducer.java:67)

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.