@@ -96,9 +96,9 @@ public class KafkaMessageListenerContainer<K, V> extends AbstractMessageListener
96
96
97
97
private final TopicPartitionInitialOffset [] topicPartitions ;
98
98
99
- private ListenerConsumer listenerConsumer ;
99
+ private volatile ListenerConsumer listenerConsumer ;
100
100
101
- private ListenableFuture <?> listenerConsumerFuture ;
101
+ private volatile ListenableFuture <?> listenerConsumerFuture ;
102
102
103
103
private GenericMessageListener <?> listener ;
104
104
@@ -153,11 +153,17 @@ public void setClientIdSuffix(String clientIdSuffix) {
153
153
* either explicitly or by Kafka; may be null if not assigned yet.
154
154
*/
155
155
public Collection <TopicPartition > getAssignedPartitions () {
156
- if (this .listenerConsumer .definedPartitions != null ) {
157
- return Collections .unmodifiableCollection (this .listenerConsumer .definedPartitions .keySet ());
158
- }
159
- else if (this .listenerConsumer .assignedPartitions != null ) {
160
- return Collections .unmodifiableCollection (this .listenerConsumer .assignedPartitions );
156
+ ListenerConsumer listenerConsumer = this .listenerConsumer ;
157
+ if (listenerConsumer != null ) {
158
+ if (listenerConsumer .definedPartitions != null ) {
159
+ return Collections .unmodifiableCollection (listenerConsumer .definedPartitions .keySet ());
160
+ }
161
+ else if (listenerConsumer .assignedPartitions != null ) {
162
+ return Collections .unmodifiableCollection (listenerConsumer .assignedPartitions );
163
+ }
164
+ else {
165
+ return null ;
166
+ }
161
167
}
162
168
else {
163
169
return null ;
@@ -267,7 +273,8 @@ private void publishNonResponsiveConsumerEvent(long timeSinceLastPoll, Consumer<
267
273
public String toString () {
268
274
return "KafkaMessageListenerContainer [id=" + getBeanName ()
269
275
+ (this .clientIdSuffix != null ? ", clientIndex=" + this .clientIdSuffix : "" )
270
- + ", topicPartitions=" + getAssignedPartitions ()
276
+ + ", topicPartitions="
277
+ + (getAssignedPartitions () == null ? "none assigned" : getAssignedPartitions ())
271
278
+ "]" ;
272
279
}
273
280
0 commit comments