Skip to content

Commit e895eb2

Browse files
committed
1 parent 20cbb8b commit e895eb2

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

spring-kafka/src/main/java/org/springframework/kafka/core/KafkaTemplate.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ public <T> T execute(ProducerCallback<K, V, T> callback) {
255255

256256
@Override
257257
public <T> T executeInTransaction(OperationsCallback<K, V, T> callback) {
258+
Assert.notNull(callback, "'callback' cannot be null");
258259
Assert.state(this.transactional, "Producer factory does not support transactions");
259260
Producer<K, V> producer = this.producers.get();
260261
Assert.state(producer == null, "Nested calls to 'executeInTransaction' are not allowed");
@@ -269,7 +270,6 @@ public <T> T executeInTransaction(OperationsCallback<K, V, T> callback) {
269270
}
270271

271272
this.producers.set(producer);
272-
T result = null;
273273
try {
274274
T result = callback.doInOperations(this);
275275
try {
@@ -284,23 +284,13 @@ public <T> T executeInTransaction(OperationsCallback<K, V, T> callback) {
284284
throw ((RuntimeException) e.getCause());
285285
}
286286
catch (Exception e) {
287-
try {
288-
producer.abortTransaction();
289-
}
290-
finally {
291-
this.producers.remove();
292-
closeProducer(producer, false);
293-
}
287+
producer.abortTransaction();
294288
throw e;
295289
}
296-
try {
297-
producer.commitTransaction();
298-
}
299290
finally {
300291
this.producers.remove();
301292
closeProducer(producer, false);
302293
}
303-
return result;
304294
}
305295

306296
/**

0 commit comments

Comments
 (0)