Skip to content

Commit 86d356c

Browse files
committed
fix REL-4
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
1 parent 671f781 commit 86d356c

File tree

1 file changed

+10
-28
lines changed

1 file changed

+10
-28
lines changed

src/main/java/org/apache/log4j/MDC.java

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,14 @@ public class MDC {
4949

5050
static final int HT_SIZE = 7;
5151

52-
boolean java1;
52+
//boolean java1;
5353

54-
Object tlm;
54+
ThreadLocalMap tlm;
5555

56-
private Method removeMethod;
5756

5857
private
5958
MDC() {
60-
java1 = Loader.isJava1();
61-
if(!java1) {
6259
tlm = new ThreadLocalMap();
63-
}
64-
65-
try {
66-
removeMethod = ThreadLocal.class.getMethod("remove", null);
67-
} catch (NoSuchMethodException e) {
68-
// don't do anything - java prior 1.5
69-
}
7060
}
7161

7262
/**
@@ -139,7 +129,7 @@ public static void clear() {
139129

140130
private
141131
void put0(String key, Object o) {
142-
if(java1 || tlm == null) {
132+
if(tlm == null) {
143133
return;
144134
} else {
145135
Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
@@ -153,10 +143,10 @@ void put0(String key, Object o) {
153143

154144
private
155145
Object get0(String key) {
156-
if(java1 || tlm == null) {
146+
if(tlm == null) {
157147
return null;
158148
} else {
159-
Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
149+
Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
160150
if(ht != null && key != null) {
161151
return ht.get(key);
162152
} else {
@@ -167,7 +157,7 @@ Object get0(String key) {
167157

168158
private
169159
void remove0(String key) {
170-
if(!java1 && tlm != null) {
160+
if(tlm != null) {
171161
Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
172162
if(ht != null) {
173163
ht.remove(key);
@@ -182,7 +172,7 @@ void remove0(String key) {
182172

183173
private
184174
Hashtable getContext0() {
185-
if(java1 || tlm == null) {
175+
if(tlm == null) {
186176
return null;
187177
} else {
188178
return (Hashtable) ((ThreadLocalMap)tlm).get();
@@ -191,21 +181,13 @@ Hashtable getContext0() {
191181

192182
private
193183
void clear0() {
194-
if(!java1 && tlm != null) {
184+
if(tlm != null) {
195185
Hashtable ht = (Hashtable) ((ThreadLocalMap)tlm).get();
196186
if(ht != null) {
197187
ht.clear();
198188
}
199-
if(removeMethod != null) {
200-
// java 1.3/1.4 does not have remove - will suffer from a memory leak
201-
try {
202-
removeMethod.invoke(tlm, null);
203-
} catch (IllegalAccessException e) {
204-
// should not happen
205-
} catch (InvocationTargetException e) {
206-
// should not happen
207-
}
208-
}
189+
190+
tlm.remove();
209191
}
210192
}
211193

0 commit comments

Comments
 (0)