-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Mqttv5PahoMessageDrivenChannelAdapter.addTopic(topic, qos) throws NPE #3732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Confirmed. Feel free to contribute the fix: https://github.com/spring-projects/spring-integration/blob/main/CONTRIBUTING.adoc Thank you! |
…ding or removing topic
…ding or removing topic
Fixes #3732 The `Mqttv5PahoMessageDrivenChannelAdapter` unconditionally tries to (un)subscribe to/from topics when the `mqqtClient` might not be initialized yet. * Add `mqqtClient` initialization check before adding or removing topic. Re-align logic with the `MqttPahoMessageDrivenChannelAdapter` **Cherry-pick to `5.5.x`**
I know I'm way too late to the party, but comparing the implementations of @artembilan Do you have an opinion on this? If so, I would provide a corresponding PR. |
@mrpiggi , I'm not sure in your question, but Would you mind to elaborate more what you see could be so generic that it can be pulled to the Thanks |
@artembilan Sorry for being a bit lazy and unspecific. Regarding Lines 222 to 238 in f013aa8
whereas Mqttv5PahoMessageDrivenChannelAdapter does:Lines 221 to 236 in f013aa8
In case of an exception, super.removeTopic() is only invoked by MqttPahoMessageDrivenChannelAdapter but not Mqttv5PahoMessageDrivenChannelAdapter , so for the latter, the topic will remain in Set<Topic> topics within AbstractMqttMessageDrivenChannelAdapter and therefore reflected by getTopic() and getQos() .
For Additionally, |
@mrpiggi , great observation and investigation! I'd be glad to see from you a PR for review. Thanks |
My analysis was incomplete. As So, only the question whether to call Line 232 in f013aa8
|
Why not vise-versa and add I doesn't look, though, that we can track failed topic somehow from the |
My intention was to get consistent behavior regardless of whether the adapter has already been initialized or not. If There is also the question of what could actually lead to a To work around this, one possibility would be to define a boolean field |
Good. If you have something in mind and can come up with some unit test to verify that behavior, I won't mind to review your contribution. Thanks |
In what version(s) of Spring Integration are you seeing this issue?
5.5.9 and prior (5.5.5)
Describe the bug
Creating a new
Mqttv5PahoMessageDrivenChannelAdapter
and usingaddTopic(topic, qos)
beforeonInit()
was called throws a NPE asthis.mqttClient.subscribe(topic, qos)
is invoked. Same withMqttv5PahoMessageDrivenChannelAdapter.removeTopic(String...)
andthis.mqttClient.unsubscribe(topic)
.To Reproduce
Workaround
Expected behavior
Topic registration or removal without calling
IMqttAsyncClient.subscribe(topic, qos)
orIMqttAsyncClient.unsubscribe(String...)
when not initialized yet.The comparison between
Mqttv5PahoMessageDrivenChannelAdapter
andMqttPahoMessageDrivenChannelAdapter
is quite obvious.spring-integration/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/Mqttv5PahoMessageDrivenChannelAdapter.java
Lines 214 to 242 in 8c57cb7
spring-integration/spring-integration-mqtt/src/main/java/org/springframework/integration/mqtt/inbound/MqttPahoMessageDrivenChannelAdapter.java
Lines 222 to 255 in 8c57cb7
The text was updated successfully, but these errors were encountered: