(parentValue);
}
- }
-
- static boolean IS_JDK14 = isJDK14();
+ };
/**
* Put a context value (the val
parameter) as identified with
* the key
parameter into the current thread's context map.
* Note that contrary to log4j, the val
parameter can be null.
- *
+ *
*
* If the current thread does not have a context map it is created as a side
* effect of this call.
- *
+ *
* @throws IllegalArgumentException
* in case the "key" parameter is null
*/
@@ -73,9 +71,9 @@
if (key == null) {
throw new IllegalArgumentException("key cannot be null");
}
- Map map = (Map) inheritableThreadLocal.get();
+ Map map = inheritableThreadLocal.get();
if (map == null) {
- map = Collections. synchronizedMap(new HashMap());
+ map = new HashMap();
inheritableThreadLocal.set(map);
}
map.put(key, val);
@@ -85,9 +83,9 @@
* Get the context identified by the key
parameter.
*/
public String get(String key) {
- Map Map = (Map) inheritableThreadLocal.get();
- if ((Map != null) && (key != null)) {
- return (String) Map.get(key);
+ Map map = inheritableThreadLocal.get();
+ if ((map != null) && (key != null)) {
+ return map.get(key);
} else {
return null;
}
@@ -97,7 +95,7 @@
* Remove the the context identified by the key
parameter.
*/
public void remove(String key) {
- Map map = (Map) inheritableThreadLocal.get();
+ Map map = inheritableThreadLocal.get();
if (map != null) {
map.remove(key);
}
@@ -107,27 +105,21 @@
* Clear all entries in the MDC.
*/
public void clear() {
- Map map = (Map) inheritableThreadLocal.get();
+ Map map = inheritableThreadLocal.get();
if (map != null) {
map.clear();
- // the InheritableThreadLocal.remove method was introduced in JDK 1.5
- // Thus, invoking clear() on previous JDK 1.4 will fail
- if (isJDK14()) {
- inheritableThreadLocal.set(null);
- } else {
- inheritableThreadLocal.remove();
- }
+ inheritableThreadLocal.remove();
}
}
/**
* Returns the keys in the MDC as a {@link Set} of {@link String}s The
* returned value can be null.
- *
+ *
* @return the keys in the MDC
*/
public Set getKeys() {
- Map map = (Map) inheritableThreadLocal.get();
+ Map map = inheritableThreadLocal.get();
if (map != null) {
return map.keySet();
} else {
@@ -136,26 +128,20 @@
}
/**
- * Return a copy of the current thread's context map.
+ * Return a copy of the current thread's context map.
* Returned value may be null.
- *
+ *
*/
public Map getCopyOfContextMap() {
- Map oldMap = (Map) inheritableThreadLocal.get();
+ Map oldMap = inheritableThreadLocal.get();
if (oldMap != null) {
- Map newMap = Collections. synchronizedMap(new HashMap());
- synchronized (oldMap) {
- newMap.putAll(oldMap);
- }
- return newMap;
+ return new HashMap(oldMap);
} else {
return null;
}
}
public void setContextMap(Map contextMap) {
- Map map = Collections. synchronizedMap(new HashMap(contextMap));
- inheritableThreadLocal.set(map);
+ inheritableThreadLocal.set(new HashMap(contextMap));
}
-
}
diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java
index 14b5308..7ed253d 100644
--- a/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java
+++ b/slf4j-api/src/main/java/org/slf4j/helpers/BasicMarker.java
@@ -101,7 +101,7 @@
int size = referenceList.size();
for (int i = 0; i < size; i++) {
- Marker m = (Marker) referenceList.get(i);
+ Marker m = referenceList.get(i);
if (referenceToRemove.equals(m)) {
referenceList.remove(i);
return true;
@@ -120,8 +120,7 @@
}
if (hasReferences()) {
- for (int i = 0; i < referenceList.size(); i++) {
- Marker ref = (Marker) referenceList.get(i);
+ for (Marker ref : referenceList) {
if (ref.contains(other)) {
return true;
}
@@ -143,8 +142,7 @@
}
if (hasReferences()) {
- for (int i = 0; i < referenceList.size(); i++) {
- Marker ref = (Marker) referenceList.get(i);
+ for (Marker ref : referenceList) {
if (ref.contains(name)) {
return true;
}
@@ -182,7 +180,7 @@
StringBuilder sb = new StringBuilder(this.getName());
sb.append(' ').append(OPEN);
while (it.hasNext()) {
- reference = (Marker) it.next();
+ reference = it.next();
sb.append(reference.getName());
if (it.hasNext()) {
sb.append(SEP);
diff --git a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
index 2fa5435..d5a5051 100644
--- a/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
+++ b/slf4j-api/src/main/java/org/slf4j/helpers/MessageFormatter.java
@@ -203,34 +203,34 @@
return new FormattingTuple(messagePattern, argArray, throwableCandidate);
} else { // add the tail string which contains no variables and return
// the result.
- sbuf.append(messagePattern.substring(i, messagePattern.length()));
+ sbuf.append(messagePattern, i, messagePattern.length());
return new FormattingTuple(sbuf.toString(), argArray, throwableCandidate);
}
} else {
if (isEscapedDelimeter(messagePattern, j)) {
if (!isDoubleEscaped(messagePattern, j)) {
L--; // DELIM_START was escaped, thus should not be incremented
- sbuf.append(messagePattern.substring(i, j - 1));
+ sbuf.append(messagePattern, i, j - 1);
sbuf.append(DELIM_START);
i = j + 1;
} else {
// The escape character preceding the delimiter start is
// itself escaped: "abc x:\\{}"
// we have to consume one backward slash
- sbuf.append(messagePattern.substring(i, j - 1));
+ sbuf.append(messagePattern, i, j - 1);
deeplyAppendParameter(sbuf, argArray[L], new HashMap