Skip to content

Commit 92e9115

Browse files
committed
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.
1 parent 9d77f55 commit 92e9115

File tree

10 files changed

+66
-4
lines changed

10 files changed

+66
-4
lines changed

log4j-samples-graalvm/src/main/resources/log4j2-jtl.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
</Appenders>
2727
<Loggers>
2828
<Root level="TRACE">
29+
<!--
30+
Added solely to verify the reachability-metadata regression (issue #3871).
31+
This configuration is not intended for production use: relying on ThresholdFilter
32+
instead of the more efficient built-in level checks is discouraged.
33+
34+
See: https://github.com/apache/logging-log4j2/issues/3871
35+
-->
36+
<ThresholdFilter level="DEBUG"/>
2937
<AppenderRef ref="FILE"/>
3038
</Root>
3139
</Loggers>

log4j-samples-graalvm/src/main/resources/log4j2.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@
2626
</Appenders>
2727
<Loggers>
2828
<Root level="TRACE">
29+
<!--
30+
Added solely to verify the reachability-metadata regression (issue #3871).
31+
This configuration is not intended for production use: relying on ThresholdFilter
32+
instead of the more efficient built-in level checks is discouraged.
33+
34+
See: https://github.com/apache/logging-log4j2/issues/3871
35+
-->
36+
<ThresholdFilter level="DEBUG"/>
2937
<AppenderRef ref="FILE"/>
3038
</Root>
3139
</Loggers>

log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/Log4j2Plugins.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@
110110
"builderHierarchy": [
111111
"org.apache.logging.log4j.layout.template.json.JsonTemplateLayout$EventTemplateAdditionalField$Builder"
112112
]
113+
},
114+
"org.apache.logging.log4j.core.filter.ThresholdFilter": {
115+
"pluginNames": [
116+
"thresholdfilter"
117+
],
118+
"elementName": "filter",
119+
"printable": true,
120+
"defer": false,
121+
"builderHierarchy": []
113122
}
114123
},
115124
"jsontemplateresolverfactory": {

log4j-samples-graalvm/src/reachability-metadata/log4j-core-jtl-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,5 +628,19 @@
628628
"name": "propertyArray"
629629
}
630630
]
631+
},
632+
{
633+
"name": "org.apache.logging.log4j.core.filter.ThresholdFilter",
634+
"methods": [
635+
{
636+
"name": "createFilter",
637+
"parameterTypes": [
638+
"org.apache.logging.log4j.Level",
639+
"org.apache.logging.log4j.core.Filter$Result",
640+
"org.apache.logging.log4j.core.Filter$Result"
641+
]
642+
}
643+
],
644+
"fields": []
631645
}
632-
]
646+
]

log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/Log4j2Plugins.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,15 @@
506506
"builderHierarchy": [
507507
"org.apache.logging.log4j.core.layout.PatternLayout$Builder"
508508
]
509+
},
510+
"org.apache.logging.log4j.core.filter.ThresholdFilter": {
511+
"pluginNames": [
512+
"thresholdfilter"
513+
],
514+
"elementName": "filter",
515+
"printable": true,
516+
"defer": false,
517+
"builderHierarchy": []
509518
}
510519
},
511520
"typeconverter": {

log4j-samples-graalvm/src/reachability-metadata/log4j-core-minimal/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1316,5 +1316,19 @@
13161316
}
13171317
],
13181318
"fields": []
1319+
},
1320+
{
1321+
"name": "org.apache.logging.log4j.core.filter.ThresholdFilter",
1322+
"methods": [
1323+
{
1324+
"name": "createFilter",
1325+
"parameterTypes": [
1326+
"org.apache.logging.log4j.Level",
1327+
"org.apache.logging.log4j.core.Filter$Result",
1328+
"org.apache.logging.log4j.core.Filter$Result"
1329+
]
1330+
}
1331+
],
1332+
"fields": []
13191333
}
1320-
]
1334+
]

log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/JsonTemplateLayoutIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
class JsonTemplateLayoutIT {
3535

36-
static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG", "TRACE"};
36+
static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG"};
3737

3838
@Test
3939
void verifyStdOut() {

log4j-samples-graalvm/src/test/java/org/apache/logging/log4j/samples/graalvm/StandardIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
*/
3333
class StandardIT {
3434

35-
static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG", "TRACE"};
35+
static final String[] STANDARD_LEVELS = {"ERROR", "WARN", "INFO", "DEBUG"};
3636

3737
@Test
3838
void verifyStdOut() {

0 commit comments

Comments
 (0)