Skip to content

Commit 1db195d

Browse files
garydgregoryppkarwasz
authored andcommitted
Possible NullPointerException in MongoDb4
1 parent 12e6c28 commit 1db195d

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

log4j-core/src/main/java/org/apache/logging/log4j/core/appender/nosql/DefaultNoSqlObject.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,25 @@ public void set(final String field, final Object value) {
4242

4343
@Override
4444
public void set(final String field, final NoSqlObject<Map<String, Object>> value) {
45-
this.map.put(field, value.unwrap());
45+
this.map.put(field, value != null ? value.unwrap() : null);
4646
}
4747

4848
@Override
4949
public void set(final String field, final Object[] values) {
50-
this.map.put(field, Arrays.asList(values));
50+
this.map.put(field, values != null ? Arrays.asList(values) : null);
5151
}
5252

5353
@Override
5454
public void set(final String field, final NoSqlObject<Map<String, Object>>[] values) {
55-
final List<Map<String, Object>> list = new ArrayList<>(values.length);
56-
for (final NoSqlObject<Map<String, Object>> value : values) {
57-
list.add(value.unwrap());
55+
if (values == null) {
56+
this.map.put(field, null);
57+
} else {
58+
final List<Map<String, Object>> list = new ArrayList<>(values.length);
59+
for (final NoSqlObject<Map<String, Object>> value : values) {
60+
list.add(value.unwrap());
61+
}
62+
this.map.put(field, list);
5863
}
59-
this.map.put(field, list);
6064
}
6165

6266
@Override

log4j-mongodb4/src/main/java/org/apache/logging/log4j/mongodb4/MongoDb4DocumentObject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public MongoDb4DocumentObject() {
3333

3434
@Override
3535
public void set(final String field, final NoSqlObject<Document> value) {
36-
this.document.append(field, value.unwrap());
36+
this.document.append(field, value != null ? value.unwrap() : null);
3737
}
3838

3939
@Override
4040
public void set(final String field, final NoSqlObject<Document>[] values) {
41-
this.document.append(field, Arrays.asList(values));
41+
this.document.append(field, values != null ? Arrays.asList(values) : null);
4242
}
4343

4444
@Override
@@ -48,7 +48,7 @@ public void set(final String field, final Object value) {
4848

4949
@Override
5050
public void set(final String field, final Object[] values) {
51-
this.document.append(field, Arrays.asList(values));
51+
this.document.append(field, values != null ? Arrays.asList(values) : null);
5252
}
5353

5454
@Override
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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-3392" link="https://issues.apache.org/jira/browse/LOG4J2-3392"/>
23+
<author id="ggregory"/>
24+
<author name="Gary Gregory"/>
25+
<description format="asciidoc">Possible NullPointerException in MongoDb4DocumentObject, MongoDbDocumentObject, DefaultNoSqlObject.</description>
26+
</entry>

0 commit comments

Comments
 (0)