[
https://issues.apache.org/jira/browse/LOG4J2-2177?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16312108#comment-16312108
]
Gary Gregory commented on LOG4J2-2177:
--------------------------------------
The only change to SASM is:
{noformat}
diff --git
a/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java
b/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java
index b54dc1b..05739f2 100644
---
a/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java
+++
b/log4j-api/src/main/java/org/apache/logging/log4j/util/SortedArrayStringMap.java
@@ -138,10 +138,10 @@
}
public SortedArrayStringMap(final int initialCapacity) {
- if (initialCapacity < 1) {
+ if (initialCapacity < 0) {
throw new IllegalArgumentException("Initial capacity must be at
least one but was " + initialCapacity);
}
- threshold = ceilingNextPowerOfTwo(initialCapacity);
+ threshold = ceilingNextPowerOfTwo(initialCapacity == 0 ? 1 :
initialCapacity);
}
public SortedArrayStringMap(final ReadOnlyStringMap other) {
{noformat}
That seems quite reasonable to me. There are cases where you want a size 0 map
just like a HashMap. I assume that the "1 for empty" as in the old init of
{{org.apache.logging.log4j.core.impl.ContextDataFactory.EMPTY_STRING_MAP}} was
a hack due to the implementation of
{{org.apache.logging.log4j.util.SortedArrayStringMap.ceilingNextPowerOfTwo(int)}}.
This old init in {{org.apache.logging.log4j.core.impl.ContextDataFactory}}
smelled awful (to me):
{code:java}
private static final IndexedStringMap EMPTY_STRING_MAP = createContextData(1);
{code}
This has now been fixed to the more natural:
{code:java}
private static final IndexedStringMap EMPTY_STRING_MAP = createContextData(0);
{code}
There was at least one test that checked for an empty map; which was not
possible before this change.
> Replace use of deprecated Core API
> org.apache.logging.log4j.core.impl.Log4jLogEvent.Builder.setContextMap(Map<String,
> String>)
> ------------------------------------------------------------------------------------------------------------------------------
>
> Key: LOG4J2-2177
> URL: https://issues.apache.org/jira/browse/LOG4J2-2177
> Project: Log4j 2
> Issue Type: Improvement
> Components: Core
> Affects Versions: 2.10.0
> Reporter: Gary Gregory
> Assignee: Gary Gregory
>
> Replace use of deprecated Core API
> {{org.apache.logging.log4j.core.impl.Log4jLogEvent.Builder.setContextMap(Map<String,
> String>)}}
> In order to implement this cleanly, the internal class
> {{org.apache.logging.log4j.core.impl.ContextDataFactory}} will change its API
> return values from {{StringMap}} to {{IndexedStringMap}}.
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)