# NPE in JmsConnector when stream is closed before

**URL:** <https://discuss.akka.io/t/npe-in-jmsconnector-when-stream-is-closed-before/4989>\
**Category:** Akka Streams & Alpakka\
**Created:** [September 4, 2019, 6:49pm UTC](https://discuss.akka.io/t/npe-in-jmsconnector-when-stream-is-closed-before/4989 "2019-09-04T18:49:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrbald](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/mrbald/32/1770_2.png) [@mrbald](https://discuss.akka.io/u/mrbald)\
**Post date:** [September 4, 2019, 6:49pm UTC](https://discuss.akka.io/t/npe-in-jmsconnector-when-stream-is-closed-before/4989/1 "2019-09-04T18:49:53Z")

</div>

When terminating JmsConsumer stream via JmsConsumerControl.shutdown() just after it’s materialized getting NPE in akka.stream.alpakka.jms.impl.JmsConnector#updateStateWith in the statement “connectionStateQueue.offer(connectionState)”, connectionStateQueue is null.

Is it a bug or I am misusing it?

---

<div class="post-metadata">

**Author:** ![ennru](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/ennru/32/1495_2.png) [@ennru](https://discuss.akka.io/u/ennru)\
**Post date:** [September 6, 2019, 3:32pm UTC](https://discuss.akka.io/t/npe-in-jmsconnector-when-stream-is-closed-before/4989/2 "2019-09-06T15:32:37Z")

</div>

Hi mrbald,

It’s a bit of both. You’re asking for it to shutdown too fast…  
The current implementation initiates the `connectionStateQueue` in `preStart` which will get called quite early, but not fast enough so that you can call `shutdown` immediately after creating the JMS consumer.

To protect against this, the `connectionStateQueue` should get assigned some dummy implementation which is almost immediately overwritten in `preStart`.

Feel free to suggest that in a Pull Request.

Cheers,  
Enno.
