You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by pk...@apache.org on 2025/12/11 16:51:46 UTC
(logging-log4j-samples) branch fix/3871_graalvm-filter created (now 40b1aa6)
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a change to branch fix/3871_graalvm-filter
in repository https://gitbox.apache.org/repos/asf/logging-log4j-samples.git
at 40b1aa6 Reproduce `ThresholdFilter` GraalVM issue
This branch includes the following new commits:
new 40b1aa6 Reproduce `ThresholdFilter` GraalVM issue
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(logging-log4j-samples) 01/01: Reproduce `ThresholdFilter` GraalVM issue
Posted by pk...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch fix/3871_graalvm-filter
in repository https://gitbox.apache.org/repos/asf/logging-log4j-samples.git
commit 40b1aa6c74869af37d6d5b6f9a481677e30b4595
Author: Piotr P. Karwasz <pk...@apache.org>
AuthorDate: Thu Dec 11 17:51:23 2025 +0100
Reproduce `ThresholdFilter` GraalVM issue
This change reproduces the issue described in apache/logging-log4j2#3871, where configurations that include `ThresholdFilter` (or any other Log4j filter) fail to work correctly when building a GraalVM native image.
The root cause is a mismatch in how parameter types are represented in `reflect-config.json`:
* The existing metadata stores parameter types using their canonical class name (JLS §6.7).
* However, GraalVM expects the binary class name (JLS §13.1).
This is especially relevant for nested types:
* Canonical name: `org.apache.logging.log4j.core.Filter.Result`
* Binary name: `org.apache.logging.log4j.core.Filter$Result`
* For array types, GraalVM accepts either:
* the JVM descriptor form (`[L<component_type>;`), or
* the Java-like form (`<component_type>[]`).
This PR introduces tests that intentionally fail for the `log4j-core` and `log4j-core-jtl` profiles, because they rely on the embedded reachability metadata in Log4j Core, which currently uses canonical names.
In contrast, the `log4j-core-minimal` and `log4j-core-jtl-minimal` profiles rely on manually generated metadata, which has been updated in this PR to use the expected binary names and now works correctly under GraalVM.
---
.../src/main/resources/log4j2-jtl.xml | 8 ++++++++
log4j-samples-graalvm/src/main/resources/log4j2.xml | 8 ++++++++
.../log4j-core-jtl-minimal/Log4j2Plugins.json | 9 +++++++++
.../log4j-core/reflect-config.json | 14 ++++++++++++++
.../log4j/core/config/plugins/Log4j2Plugins.dat | Bin 6630 -> 6711 bytes
.../log4j-core-minimal/Log4j2Plugins.json | 9 +++++++++
.../log4j-core/reflect-config.json | 14 ++++++++++++++
.../log4j/core/config/plugins/Log4j2Plugins.dat | Bin 8517 -> 8598 bytes
.../log4j/samples/graalvm/JsonTemplateLayoutIT.java | 2 +-
.../logging/log4j/samples/graalvm/StandardIT.java | 2 +-
10 files changed, 64 insertions(+), 2 deletions(-)
diff --git a/log4j-samples-graalvm/src/main/resources/log4j2-jtl.xml b/log4j-samples-graalvm/src/main/resources/log4j2-jtl.xml
index b313231..38d6097 100644
--- a/log4j-samples-graalvm/src/main/resources/log4j2-jtl.xml
+++ b/log4j-samples-graalvm/src/main/resources/log4j2-jtl.xml
@@ -26,6 +26,14 @@
</Appenders>
<Loggers>
<Root level="TRACE">
+ <!--
+ Added solely to verify the reachability-metadata regression (issue #3871).
+ This configuration is not intended for production use: relying on ThresholdFilter
+ instead of the more efficient built-in level checks is discouraged.
+
+ See: https://github.com/apache/logging-log4j2/issues/3871
+ -->
+ <ThresholdFilter level="DEBUG"/>
<AppenderRef ref="FILE"/>
</Root>
</Loggers>
diff --git a/log4j-samples-graalvm/src/main/resources/log4j2.xml b/log4j-samples-graalvm/src/main/resources/log4j2.xml
index 03a9c22..1e2be3f 100644
--- a/log4j-samples-graalvm/src/main/resources/log4j2.xml
+++ b/log4j-samples-graalvm/src/main/resources/log4j2.xml
@@ -26,6 +26,14 @@
</Appenders>
<Loggers>
<Root level="TRACE">
+ <!--
+ Added solely to verify the reachability-metadata regression (issue #3871).
+ This configuration is not intended for production use: relying on ThresholdFilter
+ instead of the more efficient built-in level checks is discouraged.
+
+ See: https://github.com/apache/logging-log4j2/issues/3871
+ -->
+ <ThresholdFilter level="DEBUG"/>
<AppenderRef ref="FILE"/>
</Root>
</Loggers>
diff --git a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/Log4j2Plugins.json b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/Log4j2Plugins.json
index 7812f6f..97cad07 100644
--- a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/Log4j2Plugins.json
+++ b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/Log4j2Plugins.json
@@ -110,6 +110,15 @@
"builderHierarchy": [
"org.apache.logging.log4j.layout.template.json.JsonTemplateLayout$EventTemplateAdditionalField$Builder"
]
+ },
+ "org.apache.logging.log4j.core.filter.ThresholdFilter": {
+ "pluginNames": [
+ "thresholdfilter"
+ ],
+ "elementName": "filter",
+ "printable": true,
+ "defer": false,
+ "builderHierarchy": []
}
},
"jsontemplateresolverfactory": {
diff --git a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json
index d36bb91..8ea033a 100644
--- a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json
+++ b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json
@@ -628,5 +628,19 @@
"name": "propertyArray"
}
]
+ },
+ {
+ "name": "org.apache.logging.log4j.core.filter.ThresholdFilter",
+ "methods": [
+ {
+ "name": "createFilter",
+ "parameterTypes": [
+ "org.apache.logging.log4j.Level",
+ "org.apache.logging.log4j.core.Filter$Result",
+ "org.apache.logging.log4j.core.Filter$Result"
+ ]
+ }
+ ],
+ "fields": []
}
]
\ No newline at end of file
diff --git a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
index ac9efe0..a1201b7 100644
Binary files a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat and b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat differ
diff --git a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/Log4j2Plugins.json b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/Log4j2Plugins.json
index 6da7a86..4fb44b5 100644
--- a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/Log4j2Plugins.json
+++ b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/Log4j2Plugins.json
@@ -506,6 +506,15 @@
"builderHierarchy": [
"org.apache.logging.log4j.core.layout.PatternLayout$Builder"
]
+ },
+ "org.apache.logging.log4j.core.filter.ThresholdFilter": {
+ "pluginNames": [
+ "thresholdfilter"
+ ],
+ "elementName": "filter",
+ "printable": true,
+ "defer": false,
+ "builderHierarchy": []
}
},
"typeconverter": {
diff --git a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json
index e9991af..2a85784 100644
--- a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json
+++ b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json
@@ -1316,5 +1316,19 @@
}
],
"fields": []
+ },
+ {
+ "name": "org.apache.logging.log4j.core.filter.ThresholdFilter",
+ "methods": [
+ {
+ "name": "createFilter",
+ "parameterTypes": [
+ "org.apache.logging.log4j.Level",
+ "org.apache.logging.log4j.core.Filter$Result",
+ "org.apache.logging.log4j.core.Filter$Result"
+ ]
+ }
+ ],
+ "fields": []
}
]
\ No newline at end of file
diff --git a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat
index c81c04b..6d4a979 100644
Binary files a/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat and b/log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/org/apache/logging/log4j/core/config/plugins/Log4j2Plugins.dat differ
diff --git a/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/JsonTemplateLayoutIT.java b/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/JsonTemplateLayoutIT.java
index 48a05c1..ba160a7 100644
--- a/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/JsonTemplateLayoutIT.java
+++ b/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/JsonTemplateLayoutIT.java
@@ -33,7 +33,7 @@ import org.junit.jupiter.api.Test;
*/
class JsonTemplateLayoutIT {
- static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG", "TRACE"};
+ static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG"};
@Test
void verifyStdOut() {
diff --git a/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/StandardIT.java b/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/StandardIT.java
index ccb5744..088e4ea 100644
--- a/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/StandardIT.java
+++ b/log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/StandardIT.java
@@ -32,7 +32,7 @@ import org.junit.jupiter.api.Test;
*/
class StandardIT {
- static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG", "TRACE"};
+ static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG"};
@Test
void verifyStdOut() {