Skip to content

Commit b594ca8

Browse files
authored
fix: patch reload4j for Kafka 3.9.x (#1330)
* fix: patch reload4j for Kafka 3.9.x * update changelog * use StringBuilder instead of StringBuffer * fix compile error
1 parent 067070d commit b594ca8

File tree

8 files changed

+96
-1
lines changed

8 files changed

+96
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ All notable changes to this project will be documented in this file.
5757
- superset: Pin `luxon` to version 3.6.1 to fix build ([#1315], [#1316])
5858
- nifi: Use a patched version of logback to fix corrupted logs ([#1314])
5959
- zookeeper: Use a patched version of logback to fix corrupted logs ([#1320])
60+
- kafka: Use patched version of reload4j to fix corrupted logs ([#1330])
6061

6162
### Fixed
6263

@@ -124,6 +125,7 @@ All notable changes to this project will be documented in this file.
124125
[#1322]: https://github.com/stackabletech/docker-images/pull/1322
125126
[#1323]: https://github.com/stackabletech/docker-images/pull/1323
126127
[#1326]: https://github.com/stackabletech/docker-images/pull/1326
128+
[#1330]: https://github.com/stackabletech/docker-images/pull/1330
127129

128130
## [25.7.0] - 2025-07-23
129131

kafka/Dockerfile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
FROM local-image/kafka/kcat AS kcat
55
FROM local-image/kafka/kafka-opa-plugin AS kafka-opa-plugin
6-
6+
FROM local-image/shared/reload4j AS patched-reload4j
77
FROM local-image/java-devel AS kafka-builder
88

99
ARG PRODUCT_VERSION
@@ -18,8 +18,12 @@ WORKDIR /stackable
1818
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/jmx/ /stackable/jmx/
1919
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/patchable.toml /stackable/src/kafka/stackable/patches/patchable.toml
2020
COPY --chown=${STACKABLE_USER_UID}:0 kafka/stackable/patches/${PRODUCT_VERSION} /stackable/src/kafka/stackable/patches/${PRODUCT_VERSION}
21+
COPY --chown=${STACKABLE_USER_UID}:0 --from=patched-reload4j /stackable/.m2/repository /stackable/patched-reload4j-libs
2122

2223
RUN <<EOF
24+
mkdir -p /stackable/.m2/repository
25+
cp -r /stackable/patched-reload4j-libs/* /stackable/.m2/repository
26+
2327
cd "$(/stackable/patchable --images-repo-root=src checkout kafka ${PRODUCT_VERSION})"
2428

2529
NEW_VERSION="${PRODUCT_VERSION}-stackable${RELEASE_VERSION}"
@@ -78,6 +82,7 @@ COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /stackable/kcat-${KAFKA_KCAT_VE
7882
COPY --chown=${STACKABLE_USER_UID}:0 --from=kcat /licenses /licenses
7983
COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-opa-plugin /stackable/src/kafka/kafka-opa-plugin/patchable-work/worktree/${KAFKA_KAFKA_OPA_PLUGIN_VERSION}/build/libs/opa-authorizer-${KAFKA_KAFKA_OPA_PLUGIN_VERSION}-all.jar /stackable/kafka_${SCALA_VERSION}-${PRODUCT_VERSION}-stackable${RELEASE_VERSION}/libs/opa-authorizer-${KAFKA_KAFKA_OPA_PLUGIN_VERSION}-all.jar
8084
COPY --chown=${STACKABLE_USER_UID}:0 --from=kafka-opa-plugin /stackable/kafka-opa-plugin-${KAFKA_KAFKA_OPA_PLUGIN_VERSION}-src.tar.gz /stackable
85+
COPY --chown=${STACKABLE_USER_UID}:0 --from=patched-reload4j /stackable/*-src.tar.gz /stackable
8186

8287
COPY --chown=${STACKABLE_USER_UID}:0 kafka/licenses /licenses
8388

kafka/boil-config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ java-base = "21"
33
java-devel = "21"
44
"kafka/kcat" = "1.7.0"
55
"kafka/kafka-opa-plugin" = "1.5.1"
6+
"shared/reload4j" = "1.2.25"
67

78
[versions."3.7.2".build-arguments]
89
scala-version = "2.13"
@@ -13,6 +14,7 @@ java-base = "21"
1314
java-devel = "21"
1415
"kafka/kcat" = "1.7.0"
1516
"kafka/kafka-opa-plugin" = "1.5.1"
17+
"shared/reload4j" = "1.2.25"
1618

1719
[versions."3.9.1".build-arguments]
1820
scala-version = "2.13"

shared/reload4j/Dockerfile

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# syntax=docker/dockerfile:1.15.1@sha256:9857836c9ee4268391bb5b09f9f157f3c91bb15821bb77969642813b0d00518d
2+
# check=error=true
3+
4+
FROM local-image/java-devel AS builder
5+
6+
ARG PRODUCT_VERSION
7+
ARG RELEASE_VERSION
8+
ARG STACKABLE_USER_UID
9+
10+
COPY --chown=${STACKABLE_USER_UID}:0 shared/reload4j/stackable/patches/patchable.toml /stackable/src/shared/reload4j/stackable/patches/patchable.toml
11+
COPY --chown=${STACKABLE_USER_UID}:0 shared/reload4j/stackable/patches/${PRODUCT_VERSION} /stackable/src/shared/reload4j/stackable/patches/${PRODUCT_VERSION}
12+
13+
USER ${STACKABLE_USER_UID}
14+
WORKDIR /stackable
15+
16+
RUN <<EOF
17+
cd "$(/stackable/patchable --images-repo-root=src checkout shared/reload4j ${PRODUCT_VERSION})"
18+
19+
# Create snapshot of the source code including custom patches
20+
tar -czf /stackable/reload4j-${PRODUCT_VERSION}-src.tar.gz .
21+
22+
mvn --batch-mode --no-transfer-progress clean install -DskipTests -Dmaven.test.skip=true -Dmaven.javadoc.skip=true
23+
EOF

shared/reload4j/boil-config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[versions."1.2.25".local-images]
2+
java-devel = "8"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
From 124575963f02242904d655cfde7d05375c2c2d26 Mon Sep 17 00:00:00 2001
2+
From: Razvan-Daniel Mihai <[email protected]>
3+
Date: Wed, 5 Nov 2025 12:27:34 +0100
4+
Subject: fix: move buffer into function to prevent race
5+
6+
---
7+
src/main/java/org/apache/log4j/helpers/Transform.java | 4 ++--
8+
src/main/java/org/apache/log4j/xml/XMLLayout.java | 10 +---------
9+
2 files changed, 3 insertions(+), 11 deletions(-)
10+
11+
diff --git a/src/main/java/org/apache/log4j/helpers/Transform.java b/src/main/java/org/apache/log4j/helpers/Transform.java
12+
index ad77e165..5f0aba25 100644
13+
--- a/src/main/java/org/apache/log4j/helpers/Transform.java
14+
+++ b/src/main/java/org/apache/log4j/helpers/Transform.java
15+
@@ -76,11 +76,11 @@ public class Transform {
16+
/**
17+
* Ensures that embeded CDEnd strings (]]&gt;) are handled properly within message, NDC and throwable tag text.
18+
*
19+
- * @param buf StringBuffer holding the XML data to this point. The initial CDStart (&lt;![CDATA[) and final CDEnd
20+
+ * @param buf StringBuilder holding the XML data to this point. The initial CDStart (&lt;![CDATA[) and final CDEnd
21+
* (]]&gt;) of the CDATA section are the responsibility of the calling method.
22+
* @param str The String that is inserted into an existing CDATA Section within buf.
23+
*/
24+
- static public void appendEscapingCDATA(final StringBuffer buf, final String str) {
25+
+ static public void appendEscapingCDATA(final StringBuilder buf, final String str) {
26+
if (str != null) {
27+
int end = str.indexOf(CDATA_END);
28+
if (end < 0) {
29+
diff --git a/src/main/java/org/apache/log4j/xml/XMLLayout.java b/src/main/java/org/apache/log4j/xml/XMLLayout.java
30+
index 4f0d99f3..35ef30d8 100644
31+
--- a/src/main/java/org/apache/log4j/xml/XMLLayout.java
32+
+++ b/src/main/java/org/apache/log4j/xml/XMLLayout.java
33+
@@ -64,9 +64,7 @@ import java.util.Arrays;
34+
public class XMLLayout extends Layout {
35+
36+
private final int DEFAULT_SIZE = 256;
37+
- private final int UPPER_LIMIT = 2048;
38+
39+
- private StringBuffer buf = new StringBuffer(DEFAULT_SIZE);
40+
private boolean locationInfo = false;
41+
private boolean properties = false;
42+
43+
@@ -121,13 +119,7 @@ public class XMLLayout extends Layout {
44+
*/
45+
public String format(final LoggingEvent event) {
46+
47+
- // Reset working buffer. If the buffer is too large, then we need a new
48+
- // one in order to avoid the penalty of creating a large array.
49+
- if (buf.capacity() > UPPER_LIMIT) {
50+
- buf = new StringBuffer(DEFAULT_SIZE);
51+
- } else {
52+
- buf.setLength(0);
53+
- }
54+
+ StringBuilder buf = new StringBuilder(DEFAULT_SIZE);
55+
56+
// We yield to the \r\n heresy.
57+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mirror = "https://github.com/stackabletech/reload4j.git"
2+
base = "2dfce6aac8e9881f60b6c9fda3fdc1e79e2c14b3"
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
upstream = "https://github.com/qos-ch/reload4j.git"
2+
default-mirror = "https://github.com/stackabletech/reload4j.git"

0 commit comments

Comments
 (0)