Skip to content

Commit 588125d

Browse files
committed
turns the simplest approach works best
1 parent 2e3e2a9 commit 588125d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

spring-kafka/src/main/java/org/springframework/kafka/listener/KafkaMessageListenerContainer.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,15 +2239,9 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
22392239
}
22402240

22412241
private List<ConsumerRecord<K, V>> createRecordList(final ConsumerRecords<K, V> records) {
2242-
Iterator<ConsumerRecord<K, V>> iterator = records.iterator();
2243-
@SuppressWarnings("unchecked") ConsumerRecord<K, V>[] recordsArray =
2244-
(ConsumerRecord<K, V>[]) Array.newInstance(ConsumerRecord.class, records.count());
2245-
int index = 0;
2246-
while (iterator.hasNext()) {
2247-
recordsArray[index] = iterator.next();
2248-
index += 1;
2249-
}
2250-
return Arrays.asList(recordsArray);
2242+
List<ConsumerRecord<K, V>> recordList = new ArrayList<>(records.count());
2243+
records.forEach(recordList::add);
2244+
return recordList;
22512245
}
22522246

22532247
/**

spring-kafka/src/main/java/org/springframework/kafka/listener/adapter/RecordFilterStrategy.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.kafka.listener.adapter;
1818

19+
import java.util.ArrayList;
1920
import java.util.Arrays;
2021
import java.util.List;
2122

@@ -51,10 +52,9 @@ public interface RecordFilterStrategy<K, V> {
5152
* @return the filtered records.
5253
* @since 2.8
5354
*/
54-
@SuppressWarnings("unchecked")
5555
default List<ConsumerRecord<K, V>> filterBatch(List<ConsumerRecord<K, V>> records) {
56-
var recordsArray = records.stream().filter(record -> !this.filter(record)).toArray(ConsumerRecord[]::new);
57-
return Arrays.asList(recordsArray);
56+
records.removeIf(this::filter);
57+
return records;
5858
}
5959

6060
/**

0 commit comments

Comments
 (0)