Skip to content

Commit ef38f57

Browse files
committed
One more NPE fix for ContextSelector.getContext() (#1538 LOG4J2-3217)
1 parent 1b8b8d8 commit ef38f57

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/selector/ContextSelector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ default boolean hasContext(String fqcn, ClassLoader loader, boolean currentConte
7979
*/
8080
default LoggerContext getContext(String fqcn, ClassLoader loader, Map.Entry<String, Object> entry, boolean currentContext) {
8181
final LoggerContext lc = getContext(fqcn, loader, currentContext);
82-
if (lc != null) {
82+
if (lc != null && entry != null) {
8383
lc.putObject(entry.getKey(), entry.getValue());
8484
}
8585
return lc;
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one or more
4+
~ contributor license agreements. See the NOTICE file distributed with
5+
~ this work for additional information regarding copyright ownership.
6+
~ The ASF licenses this file to you under the Apache License, Version 2.0
7+
~ (the "License"); you may not use this file except in compliance with
8+
~ the License. You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xmlns="http://logging.apache.org/log4j/changelog"
20+
xsi:schemaLocation="http://logging.apache.org/log4j/changelog https://logging.apache.org/log4j/changelog-0.1.1.xsd"
21+
type="fixed">
22+
<issue id="LOG4J2-3217" link="https://issues.apache.org/jira/browse/LOG4J2-3217"/>
23+
<issue id="1538" link="https://github.com/apache/logging-log4j2/pull/1538"/>
24+
<author id="pbodnar" name="Petr Bodnár"/>
25+
<author id="vy"/>
26+
<description format="asciidoc">Fix NPE in `ContextSelector`</description>
27+
</entry>

0 commit comments

Comments
 (0)