Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,19 @@ private HashMap<String, String> getTestParameters(int numParams) {
@Test
public void testCopyAndPut() {
UnmodifiableArrayBackedMap testMap = UnmodifiableArrayBackedMap.EMPTY_MAP;
testMap = testMap.copyAndPut("1", "value1");
assertTrue(testMap.containsKey("1"));
assertEquals(testMap.get("1"), "value1");
testMap = testMap.copyAndPut("6", "value6");
assertTrue(testMap.containsKey("6"));
assertEquals(testMap.get("6"), "value6");

testMap = testMap.copyAndPut("1", "another value");
assertTrue(testMap.containsKey("1"));
assertEquals(testMap.get("1"), "another value");
testMap = testMap.copyAndPut("6", "another value");
assertTrue(testMap.containsKey("6"));
assertEquals(testMap.get("6"), "another value");

HashMap<String, String> newValues = getTestParameters();
testMap = testMap.copyAndPutAll(newValues);
assertEquals(testMap.get("1"), "value1");
assertEquals(testMap.get("4"), "value4");
assertEquals(testMap.get("6"), "another value");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ public UnmodifiableArrayBackedMap copyAndPutAll(Map<String, String> entriesToAdd
// copy the contents of the current map (if any)
if (numEntries > 0) {
System.arraycopy(backingArray, 0, newMap.backingArray, 0, numEntries * 2 + 1);
newMap.numEntries = numEntries;
}

for (Map.Entry<String, String> entry : entriesToAdd.entrySet()) {
Expand Down
8 changes: 8 additions & 0 deletions src/changelog/.2.x.x/2942_fix_ThreadContext_putAll.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://logging.apache.org/xml/ns"
xsi:schemaLocation="https://logging.apache.org/xml/ns https://logging.apache.org/xml/ns/log4j-changelog-0.xsd"
type="fixed">
<issue id="2942" link="https://github.com/apache/logging-log4j2/pull/2942"/>
<description format="asciidoc">Fix `putAll()` in the default thread context map implementation</description>
</entry>