Fix AsyncRabbitTemplate.stop() for NPE
The `this.taskScheduler` reset is done outside of the
`if (this.running) {` block causing NPE on the second `stop()` call
**Cherry-pick to 1.7.x & 1.6.x**
Conflicts:
spring-rabbit/src/test/java/org/springframework/amqp/rabbit/AsyncRabbitTemplateTests.java
Resolved.
This commit is contained in:
committed by
Gary Russell
parent
dc31942b4a
commit
840ece5362
@@ -438,10 +438,10 @@ public class AsyncRabbitTemplate implements SmartLifecycle, MessageListener, Ret
|
||||
future.setNackCause("AsyncRabbitTemplate was stopped while waiting for reply");
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
if (this.internalTaskScheduler) {
|
||||
((ThreadPoolTaskScheduler) this.taskScheduler).destroy();
|
||||
this.taskScheduler = null;
|
||||
if (this.internalTaskScheduler) {
|
||||
((ThreadPoolTaskScheduler) this.taskScheduler).destroy();
|
||||
this.taskScheduler = null;
|
||||
}
|
||||
}
|
||||
this.running = false;
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||
|
||||
/**
|
||||
* @author Gary Russell
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @since 1.6
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@@ -252,6 +254,8 @@ public class AsyncRabbitTemplateTests {
|
||||
future.addCallback(callback);
|
||||
assertEquals(1, TestUtils.getPropertyValue(this.template, "pending", Map.class).size());
|
||||
this.template.stop();
|
||||
// Second stop() to be sure that it is idempotent
|
||||
this.template.stop();
|
||||
try {
|
||||
future.get(10, TimeUnit.SECONDS);
|
||||
fail("Expected CancellationException");
|
||||
|
||||
Reference in New Issue
Block a user