This is an automated email from the ASF dual-hosted git repository.
pkarwasz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/logging-log4j-samples.git
The following commit(s) were added to refs/heads/main by this push:
new 1a085fc Reproduce `ThresholdFilter` GraalVM issue (#385)
1a085fc is described below
commit 1a085fcb1fd68301574baec880cfaf1b0324acec
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Mon Dec 15 10:07:41 2025 +0100
Reproduce `ThresholdFilter` GraalVM issue (#385)
* 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.
* fix: JUL and Logback tests
---
.../src/main/resources/log4j2-jtl.xml | 8 ++++++++
log4j-samples-graalvm/src/main/resources/log4j2.xml | 8 ++++++++
log4j-samples-graalvm/src/main/resources/logback.xml | 2 +-
.../src/main/resources/logging.properties | 2 +-
.../log4j-core-jtl-minimal/Log4j2Plugins.json | 9 +++++++++
.../log4j-core/reflect-config.json | 16 +++++++++++++++-
.../log4j/core/config/plugins/Log4j2Plugins.dat | Bin 6630 -> 6711 bytes
.../log4j-core-minimal/Log4j2Plugins.json | 9 +++++++++
.../log4j-core/reflect-config.json | 16 +++++++++++++++-
.../log4j/core/config/plugins/Log4j2Plugins.dat | Bin 8517 -> 8598 bytes
.../log4j/samples/graalvm/JsonTemplateLayoutIT.java | 2 +-
.../logging/log4j/samples/graalvm/StandardIT.java | 2 +-
12 files changed, 68 insertions(+), 6 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/main/resources/logback.xml
b/log4j-samples-graalvm/src/main/resources/logback.xml
index 31bf7de..057e613 100644
--- a/log4j-samples-graalvm/src/main/resources/logback.xml
+++ b/log4j-samples-graalvm/src/main/resources/logback.xml
@@ -24,7 +24,7 @@
</encoder>
</appender>
- <root level="TRACE">
+ <root level="DEBUG">
<appender-ref ref="FILE" />
</root>
</configuration>
diff --git a/log4j-samples-graalvm/src/main/resources/logging.properties
b/log4j-samples-graalvm/src/main/resources/logging.properties
index 3070627..d9f00d7 100644
--- a/log4j-samples-graalvm/src/main/resources/logging.properties
+++ b/log4j-samples-graalvm/src/main/resources/logging.properties
@@ -16,7 +16,7 @@
#
##
handlers = java.util.logging.FileHandler
-.level = FINER
+.level = FINE
java.util.logging.FileHandler.pattern = target/logs/file.log
java.util.logging.FileHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %4$s %3$s - %5$s%n
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..0b7844e 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..4b2c518 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() {