Skip to content

Commit cab8ae8

Browse files
authored
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.
1 parent 6cd74a8 commit cab8ae8

File tree

6 files changed

+159
-2
lines changed

6 files changed

+159
-2
lines changed

log4j-api/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-api/resource-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
}
77
]
88
}
9-
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
[
2+
{
3+
"name": "org.apache.logging.log4j.core.config.builder.impl.BuiltConfiguration",
4+
"methods": [
5+
{
6+
"name": "<init>",
7+
"parameterTypes": [
8+
"org.apache.logging.log4j.core.LoggerContext",
9+
"org.apache.logging.log4j.core.config.ConfigurationSource",
10+
"org.apache.logging.log4j.core.config.builder.api.Component"
11+
]
12+
}
13+
],
14+
"fields": []
15+
},
16+
{
17+
"name": "org.apache.logging.log4j.core.config.properties.PropertiesConfiguration",
18+
"methods": [
19+
{
20+
"name": "<init>",
21+
"parameterTypes": [
22+
"org.apache.logging.log4j.core.LoggerContext",
23+
"org.apache.logging.log4j.core.config.ConfigurationSource",
24+
"org.apache.logging.log4j.core.config.builder.api.Component"
25+
]
26+
}
27+
],
28+
"fields": []
29+
},
30+
{
31+
"name": "org.apache.logging.log4j.core.async.BasicAsyncLoggerContextSelector",
32+
"methods": [
33+
{
34+
"name": "<init>",
35+
"parameterTypes": []
36+
}
37+
]
38+
},
39+
{
40+
"name": "org.apache.logging.log4j.core.selector.BasicContextSelector",
41+
"methods": [
42+
{
43+
"name": "<init>",
44+
"parameterTypes": []
45+
}
46+
]
47+
},
48+
{
49+
"name": "org.apache.logging.log4j.core.selector.JndiContextSelector",
50+
"methods": [
51+
{
52+
"name": "<init>",
53+
"parameterTypes": []
54+
}
55+
]
56+
},
57+
{
58+
"name": "org.apache.logging.log4j.core.selector.ClassLoaderContextSelector",
59+
"methods": [
60+
{
61+
"name": "<init>",
62+
"parameterTypes": []
63+
}
64+
]
65+
},
66+
{
67+
"name": "org.apache.logging.log4j.core.async.AsyncLoggerContextSelector",
68+
"methods": [
69+
{
70+
"name": "<init>",
71+
"parameterTypes": []
72+
}
73+
]
74+
},
75+
{
76+
"name": "org.apache.logging.log4j.core.osgi.BundleContextSelector",
77+
"methods": [
78+
{
79+
"name": "<init>",
80+
"parameterTypes": []
81+
}
82+
]
83+
},
84+
{
85+
"name": "org.apache.logging.log4j.core.config.LockingReliabilityStrategy",
86+
"methods": [
87+
{
88+
"name": "<init>",
89+
"parameterTypes": []
90+
}
91+
]
92+
},
93+
{
94+
"name": "org.apache.logging.log4j.core.config.AwaitUnconditionallyReliabilityStrategy",
95+
"methods": [
96+
{
97+
"name": "<init>",
98+
"parameterTypes": []
99+
}
100+
]
101+
},
102+
{
103+
"name": "org.apache.logging.log4j.core.config.DefaultReliabilityStrategy",
104+
"methods": [
105+
{
106+
"name": "<init>",
107+
"parameterTypes": []
108+
}
109+
]
110+
},
111+
{
112+
"name": "org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy",
113+
"methods": [
114+
{
115+
"name": "<init>",
116+
"parameterTypes": []
117+
}
118+
]
119+
}
120+
]

log4j-core/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-core/resource-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
}
1010
]
1111
}
12-
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[
2+
{
3+
"name": "org.jctools.queues.MpmcArrayQueue",
4+
"methods": [
5+
{
6+
"name": "<init>",
7+
"parameterTypes": [
8+
"int"
9+
]
10+
}
11+
]
12+
},
13+
{
14+
"name": "java.util.concurrent.ArrayBlockingQueue",
15+
"methods": [
16+
{
17+
"name": "<init>",
18+
"parameterTypes": [
19+
"int"
20+
]
21+
}
22+
]
23+
}
24+
]

log4j-layout-template-json/src/main/resources/META-INF/native-image/org.apache.logging.log4j/log4j-layout-template-json/resource-config.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
]
88
}
99
}
10+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<entry xmlns="https://logging.apache.org/xml/ns"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="
5+
https://logging.apache.org/xml/ns
6+
https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
7+
type="fixed">
8+
<issue id="3800" link="https://github.com/apache/logging-log4j2/pull/3800"/>
9+
<description format="asciidoc">
10+
Resolves `PropertiesConfiguration` compatibility issues with GraalVM and addresses additional minor reflection-related problems.
11+
</description>
12+
</entry>

0 commit comments

Comments
 (0)