Skip to content

Commit 665a345

Browse files
committed
feat: Replace LinkedList with ArrayList
As per #3764 Signed-off-by: Janek Lasocki-Biczysko <[email protected]>
1 parent 23eed85 commit 665a345

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

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

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

1717
package org.springframework.kafka.listener;
1818

19+
import java.lang.reflect.Array;
1920
import java.nio.ByteBuffer;
2021
import java.time.Duration;
2122
import java.util.AbstractMap.SimpleEntry;
@@ -2238,11 +2239,14 @@ protected void doInTransactionWithoutResult(TransactionStatus status) {
22382239

22392240
private List<ConsumerRecord<K, V>> createRecordList(final ConsumerRecords<K, V> records) {
22402241
Iterator<ConsumerRecord<K, V>> iterator = records.iterator();
2241-
List<ConsumerRecord<K, V>> list = new LinkedList<>();
2242+
@SuppressWarnings("unchecked") ConsumerRecord<K, V>[] recordsArray =
2243+
(ConsumerRecord<K, V>[]) Array.newInstance(ConsumerRecord.class, records.count());
2244+
int index = 0;
22422245
while (iterator.hasNext()) {
2243-
list.add(iterator.next());
2246+
recordsArray[index] = iterator.next();
2247+
index += 1;
22442248
}
2245-
return list;
2249+
return Arrays.asList(recordsArray);
22462250
}
22472251

22482252
/**

0 commit comments

Comments
 (0)