Commit 9e4ba4f
GH-1148: Log4jAppender - fix initialization cycle
Resolves #1148
Defer creation of all Spring static loggers from appender until the
appender is initialized.
The first logger (e.g. Spring Boot) initializes the static `LoggerContext`
field in `LogAdapter.Log4jLog`; this, in turn initializes the appender.
However, the appender references Spring objects that have static loggers.
This causes the `Log4jLog` CTOR to be called before the field is initialized,
causing an NPE.
Defer creation of all static loggers until the appender is fully initialized.
Tested with the log4j2 sample app.
Also add a test for async sends.
**cherry-pick to 2.1.x**
* NOSONAR - inconsistent sync1 parent fb32210 commit 9e4ba4f
File tree
3 files changed
+45
-27
lines changed- spring-rabbit/src
- main/java/org/springframework/amqp/rabbit/log4j2
- test
- java/org/springframework/amqp/rabbit/log4j2
- resources
3 files changed
+45
-27
lines changedLines changed: 22 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
129 | | - | |
| 129 | + | |
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| |||
250 | 250 | | |
251 | 251 | | |
252 | 252 | | |
253 | | - | |
254 | 253 | | |
| 254 | + | |
255 | 255 | | |
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | 259 | | |
266 | 260 | | |
267 | 261 | | |
| |||
287 | 281 | | |
288 | 282 | | |
289 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
290 | 300 | | |
291 | 301 | | |
292 | 302 | | |
| |||
352 | 362 | | |
353 | 363 | | |
354 | 364 | | |
355 | | - | |
| 365 | + | |
356 | 366 | | |
357 | 367 | | |
358 | 368 | | |
| |||
645 | 655 | | |
646 | 656 | | |
647 | 657 | | |
648 | | - | |
| 658 | + | |
649 | 659 | | |
650 | 660 | | |
651 | 661 | | |
| |||
667 | 677 | | |
668 | 678 | | |
669 | 679 | | |
670 | | - | |
671 | 680 | | |
672 | 681 | | |
673 | 682 | | |
| |||
1182 | 1191 | | |
1183 | 1192 | | |
1184 | 1193 | | |
1185 | | - | |
1186 | | - | |
1187 | | - | |
1188 | | - | |
1189 | | - | |
| 1194 | + | |
| 1195 | + | |
1190 | 1196 | | |
1191 | 1197 | | |
1192 | 1198 | | |
| |||
Lines changed: 19 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
176 | | - | |
177 | | - | |
| 178 | + | |
| 179 | + | |
178 | 180 | | |
179 | 181 | | |
180 | 182 | | |
181 | 183 | | |
182 | | - | |
183 | | - | |
| 184 | + | |
| 185 | + | |
184 | 186 | | |
185 | 187 | | |
186 | 188 | | |
187 | 189 | | |
188 | | - | |
189 | | - | |
| 190 | + | |
| 191 | + | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
193 | | - | |
194 | | - | |
| 195 | + | |
| 196 | + | |
195 | 197 | | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
199 | | - | |
| 201 | + | |
200 | 202 | | |
| 203 | + | |
201 | 204 | | |
202 | 205 | | |
203 | 206 | | |
| |||
207 | 210 | | |
208 | 211 | | |
209 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
210 | 219 | | |
211 | 220 | | |
212 | 221 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
0 commit comments