This is an automated email from the ASF dual-hosted git repository. pkarwasz pushed a commit to branch 2.25.x in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
commit 21a2300d2eea08e19e849091e53e3fa238537a05 Author: Piotr P. Karwasz <[email protected]> AuthorDate: Fri Jul 4 18:43:08 2025 +0200 fix: Add GraalVM reachability metadata for non-plugin class instantiations (#3800) 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-api/resource-config.json | 2 +- .../log4j-core/reflect-config.json | 120 +++++++++++++++++++++ .../log4j-core/resource-config.json | 2 +- .../log4j-layout-template-json/reflect-config.json | 24 +++++ .../resource-config.json | 1 + .../.2.x.x/3800_graalvm-misc-reflection.xml | 12 +++ 6 files changed, 159 insertions(+), 2 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 1649e6be1e..9b4eb75dc6 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 new file mode 100644 index 0000000000..5411a855b9 --- /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": "<init>", + "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": "<init>", + "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": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.selector.BasicContextSelector", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.selector.JndiContextSelector", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.selector.ClassLoaderContextSelector", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.osgi.BundleContextSelector", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.LockingReliabilityStrategy", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.AwaitUnconditionallyReliabilityStrategy", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.DefaultReliabilityStrategy", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + }, + { + "name": "org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy", + "methods": [ + { + "name": "<init>", + "parameterTypes": [] + } + ] + } +] 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 d5b51667ed..9f1049ed8b 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 new file mode 100644 index 0000000000..c4e3872cd6 --- /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": "<init>", + "parameterTypes": [ + "int" + ] + } + ] + }, + { + "name": "java.util.concurrent.ArrayBlockingQueue", + "methods": [ + { + "name": "<init>", + "parameterTypes": [ + "int" + ] + } + ] + } +] 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 c8afe14794..55c503ebeb 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 @@ ] } } + 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 0000000000..3e6653c121 --- /dev/null +++ b/src/changelog/.2.x.x/3800_graalvm-misc-reflection.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<entry xmlns="https://logging.apache.org/xml/ns" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + https://logging.apache.org/xml/ns + https://logging.apache.org/xml/ns/log4j-changelog-0.xsd" + type="fixed"> + <issue id="3800" link="https://github.com/apache/logging-log4j2/pull/3800"/> + <description format="asciidoc"> + Resolves `PropertiesConfiguration` compatibility issues with GraalVM and addresses additional minor reflection-related problems. + </description> +</entry>
