From c2fd11fefdbba243faa48c673a5f89e41d90482c Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 3 Jul 2025 21:17:46 +0200 Subject: [PATCH 1/3] fix: Add GraalVM reachability metadata for non-plugin class instantiations** MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `GraalVmProcessor` currently only generates metadata for Log4j plugins, overlooking other reflection usages in Log4j Core. This change adds reachability metadata for additional reflection cases to improve compatibility with GraalVM native images. ### Fixed Cases This PR addresses the following reflective instantiations: * **Context selectors and reliability strategies:** Ensures proper instantiation under GraalVM. * **`Configuration` instantiation in `DefaultConfigurationBuilder`:** Fixes support for the `log4j2.properties` configuration format when running on GraalVM. * **`BlockingQueue` instantiation in JSON Template Layout:** Enables GraalVM compatibility. Note: `MpmcArrayQueue` is not supported on GraalVM and must be fixed in the JCTools project. ### Known Limitations (Explicitly Ignored) The following cases are *not* addressed in this PR: * **JMX classes in `log4j-1.2-api`:** While GraalVM supports JMX, usage of Log4j 1.x’s JMX interface is likely minimal. * **`MulticastDnsAdvertiser`:** This feature is probably unused and could pose a security risk by advertising log file locations via mDNS. --- .../log4j-core/reflect-config.json | 120 ++++++++++++++++++ .../reflect-config.json | 24 ++++ 2 files changed, 144 insertions(+) create mode 100644 log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json create mode 100644 log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json diff --git a/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json b/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json new file mode 100644 index 00000000000..a13a5ee5ff8 --- /dev/null +++ b/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json @@ -0,0 +1,120 @@ +[ + { + "name": "org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration", + "methods": [ + { + "name": "", + "parameterTypes": [ + "org.apache.logging.log4j.core.LoggerContext", + "org.apache.logging.log4j.core.config.ConfigurationSource", + "org.apache.logging.log4j.core.config.builder.api.Component" + ] + } + ], + "fields": [] + }, + { + "name": "org.apache.logging.log4j.core.config.properties.PropertiesConfiguration", + "methods": [ + { + "name": "", + "parameterTypes": [ + "org.apache.logging.log4j.core.LoggerContext", + "org.apache.logging.log4j.core.config.ConfigurationSource", + "org.apache.logging.log4j.core.config.builder.api.Component" + ] + } + ], + "fields": [] + }, + { + "name": "org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.selector.BasicContextSelector", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.selector.JndiContextSelector", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.selector.ClassLoaderContextSelector", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.osgi.BundleContextSelector", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.LockingReliabilityStrategy", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.AwaitUnconditionallyReliabilityStrategy", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.DefaultReliabilityStrategy", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + } +] \ No newline at end of file diff --git a/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json b/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json new file mode 100644 index 00000000000..5d248a2d942 --- /dev/null +++ b/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json @@ -0,0 +1,24 @@ +[ + { + "name": "org.jctools.queues.MpmcArrayQueue", + "methods": [ + { + "name": "", + "parameterTypes": [ + "int" + ] + } + ] + }, + { + "name": "java.util.concurrent.ArrayBlockingQueue", + "methods": [ + { + "name": "", + "parameterTypes": [ + "int" + ] + } + ] + } +] \ No newline at end of file From 3411a8a660e9bb218a791a5e079bf95c81caad80 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Thu, 3 Jul 2025 21:21:58 +0200 Subject: [PATCH 2/3] fix: add changelog entry --- .../.2.x.x/3800_graalvm-misc-reflection.xml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/changelog/.2.x.x/3800_graalvm-misc-reflection.xml diff --git a/src/changelog/.2.x.x/3800_graalvm-misc-reflection.xml b/src/changelog/.2.x.x/3800_graalvm-misc-reflection.xml new file mode 100644 index 00000000000..3e6653c121f --- /dev/null +++ b/src/changelog/.2.x.x/3800_graalvm-misc-reflection.xml @@ -0,0 +1,12 @@ + + + + + Resolves `PropertiesConfiguration` compatibility issues with GraalVM and addresses additional minor reflection-related problems. + + From 52326ccbaf9e98fb621eee722a2b5f32d3e8e341 Mon Sep 17 00:00:00 2001 From: "Piotr P. Karwasz" Date: Fri, 4 Jul 2025 15:14:38 +0200 Subject: [PATCH 3/3] fix: add trailing EOL to JSON files --- .../org.apache.logging.log4j/log4j-api/resource-config.json | 2 +- .../org.apache.logging.log4j/log4j-core/reflect-config.json | 2 +- .../org.apache.logging.log4j/log4j-core/resource-config.json | 2 +- .../log4j-layout-template-json/reflect-config.json | 2 +- .../log4j-layout-template-json/resource-config.json | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/log4j-api/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-api/resource-config.json b/log4j-api/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-api/resource-config.json index 1649e6be1ef..9b4eb75dc63 100644 --- a/log4j-api/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-api/resource-config.json +++ b/log4j-api/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-api/resource-config.json @@ -6,4 +6,4 @@ } ] } -} \ No newline at end of file +} diff --git a/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json b/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json index a13a5ee5ff8..5411a855b98 100644 --- a/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json +++ b/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/reflect-config.json @@ -117,4 +117,4 @@ } ] } -] \ No newline at end of file +] diff --git a/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/resource-config.json b/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/resource-config.json index d5b51667ed9..9f1049ed8ba 100644 --- a/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/resource-config.json +++ b/log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/resource-config.json @@ -9,4 +9,4 @@ } ] } -} \ No newline at end of file +} diff --git a/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json b/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json index 5d248a2d942..c4e3872cd69 100644 --- a/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json +++ b/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/reflect-config.json @@ -21,4 +21,4 @@ } ] } -] \ No newline at end of file +] diff --git a/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/resource-config.json b/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/resource-config.json index c8afe14794a..55c503ebebc 100644 --- a/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/resource-config.json +++ b/log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/resource-config.json @@ -7,3 +7,4 @@ ] } } +