From 538d2233fecbd60eead7c6688ea027910e941109 Mon Sep 17 00:00:00 2001 From: Andrei Lukkonen Date: Wed, 9 Oct 2024 14:10:13 +0300 Subject: [PATCH] Fix UnsupportedOperationException when modifying headers (#93) * copy passed headers into an ArrayList before setting them to avoid UnsupportedOperationException's --- CHANGELOG.md | 5 +++++ gradle.properties | 2 +- .../com/transferwise/kafka/tkms/api/TkmsMessage.java | 12 ++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8eec1b6..1410d0c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.31.1] - 2024-10-09 + +### Fixed +- Override the lombok generated `TkmsMessage#setHeaders` to copy the passed headers into a mutable `ArrayList` in order to avoid `UnsupportedOperationException` + ## [0.31.0] - 2024-10-07 ### Changed diff --git a/gradle.properties b/gradle.properties index 229d380..516a2d2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1 +1 @@ -version=0.31.0 +version=0.31.1 diff --git a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/api/TkmsMessage.java b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/api/TkmsMessage.java index 4b66cba..14b4536 100644 --- a/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/api/TkmsMessage.java +++ b/tw-tkms-starter/src/main/java/com/transferwise/kafka/tkms/api/TkmsMessage.java @@ -6,6 +6,7 @@ import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; @@ -107,6 +108,17 @@ public TkmsMessage addPriorityHeader(long priority) { ); } + /** + * Copy the passed headers into a ModifiableList to avoid UnsupportedOperationException when `addHeader` is called. + * @param headers headers to copy + * @return TkmsMessage + */ + public TkmsMessage setHeaders(List
headers) { + this.headers = new ArrayList<>(headers); + + return this; + } + public TkmsMessage addHeader(Header header) { if (headers == null) { headers = new ArrayList<>();