title: Impossible (?) NullPointerException - Springframework RabbitMQ, Failed to invoke afterAckCallback
body: <p>I'm running a Java application that uses RabbitMQ Server 3.8.9, spring-amqp-2.2.10.RELEASE, and spring-rabbit-2.2.10.RELEASE.</p>
  <p>My test case does something like the following:</p>
  <ol>
  <li>Start the RabbitMQ Server</li>
  <li>Start my Java application</li>
  <li>Test and validate some functionality on my Java application</li>
  <li>Gracefully stop my Java application</li>
  <li>Gracefully stop the RabbitMQ Server</li>
  <li>Repeat 1-6 a few more times</li>
  </ol>
  <p>Everything looks fine except sometimes during one of the restarts about 10 minutes into it, I see the following error in my application's logs:</p>
  <pre><code>2021-02-05 12:52:46.498 UTC,ERROR,org.springframework.amqp.rabbit.connection.PublisherCallbackChannelImpl,null,rabbitConnectionFactory23,runWorker():1149,Failed to invoke afterAckCallback
  java.lang.NullPointerException: null
      at org.springframework.amqp.rabbit.connection.PublisherCallbackChannelImpl.lambda$doHandleConfirm$1(PublisherCallbackChannelImpl.java:1027) ~[spring-rabbit.jar:2.2.10.RELEASE]
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_181]
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_181]
      at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_181]
  </code></pre>
  <p>Further analysis doesn't point to anything specific. There are no errors in the RabbitMQ log files, no restarts of the RabbitMQ server, nothing weird in the RabbitMQ logs during the time stamp above.</p>
  <p>The code in question:</p>
  <p><a href="https://github.com/spring-projects/spring-amqp/blob/v2.2.10.RELEASE/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/PublisherCallbackChannelImpl.java#L1027" rel="nofollow noreferrer">https://github.com/spring-projects/spring-amqp/blob/v2.2.10.RELEASE/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/connection/PublisherCallbackChannelImpl.java#L1027</a></p>
  <p>My tests are automated and run as part of a CI pipeline. The issue is intermittent and I have had trouble reproducing it locally in my sandbox.</p>
  <p>From what I can tell, the functionality of my Java application is unaffected.</p>
  <p>Code that creates the RabbitMQ connection factory used everywhere:</p>
  <pre><code>final CachingConnectionFactory connectionFactory = new CachingConnectionFactory(HOST_NAME);
  connectionFactory.setChannelCacheSize(1);
  connectionFactory.setPublisherConfirms(true);
  </code></pre>
  <p>It seems like a concurrency problem, but I'm not so sure on how to get to the bottom of it. For the most part, we use the RabbitTemplate and other Spring facilities to connect to RabbitMQ.</p>
  <p>Anyone in the Spring world with some knowledge in RabbitMQ care to chime in?</p>
  <p>Thanks</p>