This is an automated email from the ASF dual-hosted git repository.

pkarwasz pushed a commit to branch fix/2.x/graalvm-misc-reflection
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit c2fd11fefdbba243faa48c673a5f89e41d90482c
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Thu Jul 3 21:17:46 2025 +0200

    fix: Add GraalVM reachability metadata for non-plugin class instantiations**
    
    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 +++++++++++++++++++++
 .../log4j-layout-template-json/reflect-config.json |  24 +++++
 2 files changed, 144 insertions(+)

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..a13a5ee5ff
--- /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": []
+      }
+    ]
+  }
+]
\ 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..5d248a2d94
--- /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"
+        ]
+      }
+    ]
+  }
+]
\ No newline at end of file

Reply via email to