hivemq / hivemq-mqtt-client

HiveMQ MQTT Client is an MQTT 5.0 and MQTT 3.1.1 compatible and feature-rich high-performance Java client library with different API flavours and backpressure support
https://hivemq.github.io/hivemq-mqtt-client/
Apache License 2.0
824 stars 153 forks source link

Possible run-time exception on empty response topic #607

Open jyoo980 opened 7 months ago

jyoo980 commented 7 months ago

I was looking at some code in RequestResponse.java

and noticed a call to get() here:

.topic(requestPublish.getResponseTopic().get())

will crash with a NoSuchElementException at run time if the response topic is ever an empty Optional. This appears to be a possibility, as getResponseTopic() returns an Optional.ofNullable of a nullable field responseTopic:

private final @Nullable MqttTopicImpl responseTopic;

public @NotNull Optional<MqttTopic> getResponseTopic() {
  return Optional.ofNullable(responseTopic);
}

I am happy to write a patch for this, if desired - thanks!

jyoo980 commented 1 month ago

Hi, any updates on this? I'm still happy to work with the maintainers on a patch!