3838import org .springframework .kafka .support .converter .MessageConverter ;
3939import org .springframework .kafka .support .converter .MessagingMessageConverter ;
4040import org .springframework .kafka .support .converter .RecordMessageConverter ;
41+ import org .springframework .lang .Nullable ;
4142import org .springframework .messaging .Message ;
4243import org .springframework .transaction .support .TransactionSynchronizationManager ;
4344import org .springframework .util .Assert ;
@@ -126,7 +127,7 @@ public void setDefaultTopic(String defaultTopic) {
126127 * which logs errors only.
127128 * @param producerListener the listener; may be {@code null}.
128129 */
129- public void setProducerListener (ProducerListener <K , V > producerListener ) {
130+ public void setProducerListener (@ Nullable ProducerListener <K , V > producerListener ) {
130131 this .producerListener = producerListener ;
131132 }
132133
@@ -143,6 +144,7 @@ public MessageConverter getMessageConverter() {
143144 * @param messageConverter the message converter.
144145 */
145146 public void setMessageConverter (RecordMessageConverter messageConverter ) {
147+ Assert .notNull (messageConverter , "'messageConverter' cannot be null" );
146148 this .messageConverter = messageConverter ;
147149 }
148150
@@ -157,50 +159,51 @@ public boolean isTransactional() {
157159 }
158160
159161 @ Override
160- public ListenableFuture <SendResult <K , V >> sendDefault (V data ) {
162+ public ListenableFuture <SendResult <K , V >> sendDefault (@ Nullable V data ) {
161163 return send (this .defaultTopic , data );
162164 }
163165
164166 @ Override
165- public ListenableFuture <SendResult <K , V >> sendDefault (K key , V data ) {
167+ public ListenableFuture <SendResult <K , V >> sendDefault (K key , @ Nullable V data ) {
166168 return send (this .defaultTopic , key , data );
167169 }
168170
169171 @ Override
170- public ListenableFuture <SendResult <K , V >> sendDefault (Integer partition , K key , V data ) {
172+ public ListenableFuture <SendResult <K , V >> sendDefault (Integer partition , K key , @ Nullable V data ) {
171173 return send (this .defaultTopic , partition , key , data );
172174 }
173175
174176 @ Override
175- public ListenableFuture <SendResult <K , V >> sendDefault (Integer partition , Long timestamp , K key , V data ) {
177+ public ListenableFuture <SendResult <K , V >> sendDefault (Integer partition , Long timestamp , K key , @ Nullable V data ) {
176178 return send (this .defaultTopic , partition , timestamp , key , data );
177179 }
178180
179181 @ Override
180- public ListenableFuture <SendResult <K , V >> send (String topic , V data ) {
182+ public ListenableFuture <SendResult <K , V >> send (String topic , @ Nullable V data ) {
181183 ProducerRecord <K , V > producerRecord = new ProducerRecord <>(topic , data );
182184 return doSend (producerRecord );
183185 }
184186
185187 @ Override
186- public ListenableFuture <SendResult <K , V >> send (String topic , K key , V data ) {
188+ public ListenableFuture <SendResult <K , V >> send (String topic , K key , @ Nullable V data ) {
187189 ProducerRecord <K , V > producerRecord = new ProducerRecord <>(topic , key , data );
188190 return doSend (producerRecord );
189191 }
190192
191193 @ Override
192- public ListenableFuture <SendResult <K , V >> send (String topic , Integer partition , K key , V data ) {
194+ public ListenableFuture <SendResult <K , V >> send (String topic , Integer partition , K key , @ Nullable V data ) {
193195 ProducerRecord <K , V > producerRecord = new ProducerRecord <>(topic , partition , key , data );
194196 return doSend (producerRecord );
195197 }
196198
197199 @ Override
198- public ListenableFuture <SendResult <K , V >> send (String topic , Integer partition , Long timestamp , K key , V data ) {
200+ public ListenableFuture <SendResult <K , V >> send (String topic , Integer partition , Long timestamp , K key ,
201+ @ Nullable V data ) {
202+
199203 ProducerRecord <K , V > producerRecord = new ProducerRecord <>(topic , partition , timestamp , key , data );
200204 return doSend (producerRecord );
201205 }
202206
203-
204207 @ Override
205208 public ListenableFuture <SendResult <K , V >> send (ProducerRecord <K , V > record ) {
206209 return doSend (record );
@@ -244,6 +247,7 @@ public List<PartitionInfo> partitionsFor(String topic) {
244247
245248 @ Override
246249 public <T > T execute (ProducerCallback <K , V , T > callback ) {
250+ Assert .notNull (callback , "'callback' cannot be null" );
247251 Producer <K , V > producer = getTheProducer ();
248252 try {
249253 return callback .doInKafka (producer );
@@ -255,6 +259,7 @@ public <T> T execute(ProducerCallback<K, V, T> callback) {
255259
256260 @ Override
257261 public <T > T executeInTransaction (OperationsCallback <K , V , T > callback ) {
262+ Assert .notNull (callback , "'callback' cannot be null" );
258263 Assert .state (this .transactional , "Producer factory does not support transactions" );
259264 Producer <K , V > producer = this .producers .get ();
260265 Assert .state (producer == null , "Nested calls to 'executeInTransaction' are not allowed" );
0 commit comments