You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@artemis.apache.org by "ASF subversion and git services (Jira)" <ji...@apache.org> on 2026/06/04 16:32:00 UTC

[jira] [Commented] (ARTEMIS-6085) NullPointerException calling MQTTSessionState.getSession()

    [ https://issues.apache.org/jira/browse/ARTEMIS-6085?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18086135#comment-18086135 ] 

ASF subversion and git services commented on ARTEMIS-6085:
----------------------------------------------------------

Commit cd396d02cbe66aeea2a585a4f272183676e8dc97 in artemis's branch refs/heads/dependabot/maven/com.fasterxml.jackson-jackson-bom-2.22.0 from Karol
[ https://gitbox.apache.org/repos/asf?p=artemis.git;h=cd396d02cb ]

ARTEMIS-6085 Fix NPE from race in MQTTStateManager.getSessionState

getSessionState() used a non-atomic containsKey()/get() pair on a
ConcurrentHashMap. During link stealing (two connections sharing a
client ID) removeSessionState() can run between the two calls, so get()
returns null and handleLinkStealing() dereferences it via .getSession(),
throwing a NullPointerException.

Use computeIfAbsent() for an atomic get-or-create that never returns null.
Adds a concurrency regression test that reproduces the NPE.


> NullPointerException calling MQTTSessionState.getSession()
> ----------------------------------------------------------
>
>                 Key: ARTEMIS-6085
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-6085
>             Project: Artemis
>          Issue Type: Bug
>    Affects Versions: 2.42.0
>            Reporter: Daniel Martin
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 2.55.0
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> I found this among my broker's logs:
> {noformat}
> 2026-05-28 16:19:43,429 ERROR [org.apache.activemq.artemis.core.protocol.mqtt] AMQ834002: Error processing control packet: MqttConnectMessage[fixedHeader=MqttFixedHeader[messageType=CONNECT, isDup=false, qosLevel=AT_MOST_ONCE, isRetain=false, remainingLength=99], variableHeader=MqttConnectVariableHeader[name=MQTT, version=5, hasUserName=true, hasPassword=true, isWillRetain=false, isWillFlag=false, isCleanSession=false, keepAliveTimeSeconds=30], payload=MqttConnectPayload[clientIdentifier=xyz-1, willTopic=null, willMessage=null, userName=artemis, password=[99, 50, 56, 54, 100, 56, 51, 49, 48, 98, 99, 102, 98, 49, 99, 50, 102, 57, 101, 98, 48, 49, 57, 56, 102, 100, 101, 49, 49, 56, 102, 54, 97, 52, 53, 51, 48, 57, 56, 48, 98, 99, 48, 51, 51, 99, 99, 55, 56, 100, 97, 52, 57, 97, 56, 53, 54, 98, 99, 97, 100, 55, 57, 99]]]
> java.lang.NullPointerException: Cannot invoke "org.apache.activemq.artemis.core.protocol.mqtt.MQTTSessionState.getSession()" because the return value of "org.apache.activemq.artemis.core.protocol.mqtt.MQTTStateManager.getSessionState(String)" is null
>   at org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolHandler.handleLinkStealing(MQTTProtocolHandler.java:484)
>   at org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolHandler.handleConnect(MQTTProtocolHandler.java:258)
>   at org.apache.activemq.artemis.core.protocol.mqtt.MQTTProtocolHandler.act(MQTTProtocolHandler.java:161)
>   at org.apache.activemq.artemis.utils.actors.Actor.doTask(Actor.java:32)
>   at org.apache.activemq.artemis.utils.actors.ProcessorBase.executePendingTasks(ProcessorBase.java:69)
>   at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
>   at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
>   at org.apache.activemq.artemis.utils.ActiveMQThreadFactory$1.run(ActiveMQThreadFactory.java:120){noformat}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@artemis.apache.org
For additional commands, e-mail: issues-help@artemis.apache.org