Skip to content
This repository was archived by the owner on Sep 13, 2023. It is now read-only.

Commit cdb674e

Browse files
committed
Fix old MDC java version parsing bug.
1 parent cfa9012 commit cdb674e

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,7 @@ public class MDC {
7272

7373
private MDC() {
7474
java1 = Loader.isJava1();
75-
if (!java1) {
76-
tlm = new ThreadLocalMap();
77-
}
75+
tlm = new ThreadLocalMap();
7876

7977
try {
8078
removeMethod = ThreadLocal.class.getMethod("remove", null);

src/main/java/org/apache/log4j/helpers/Loader.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,22 +33,12 @@ public class Loader {
3333

3434
static final String TSTR = "Caught Exception while in Loader.getResource. This may be innocuous.";
3535

36-
// We conservatively assume that we are running under Java 1.x
37-
static private boolean java1 = true;
36+
// We are on java 1.2+ since we compile with source/target >1.4
37+
static private final boolean java1 = false;
3838

3939
static private boolean ignoreTCL = false;
4040

4141
static {
42-
String prop = OptionConverter.getSystemProperty("java.version", null);
43-
44-
if(prop != null) {
45-
int i = prop.indexOf('.');
46-
if(i != -1) {
47-
if(prop.charAt(i+1) != '1') {
48-
java1 = false;
49-
}
50-
}
51-
}
5242
String ignoreTCLProp = OptionConverter.getSystemProperty("log4j.ignoreTCL", null);
5343
if(ignoreTCLProp != null) {
5444
ignoreTCL = OptionConverter.toBoolean(ignoreTCLProp, true);

src/site/apt/index.apt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ Java Version Incompatibilities
3232
{{{https://blogs.apache.org/logging/entry/moving_on_to_log4j_2}Log4j 1.2 is broken on Java 9}}
3333
for details.
3434

35+
Switch to Log4J >=1.2.18 to get MDC to work.
36+
3537
Apache log4j\u2122 1.2
3638

3739
Welcome to Apache log4j, a logging library for Java. Apache log4j
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package org.apache.log4j.helpers;
2+
3+
import junit.framework.TestCase;
4+
5+
public class LoaderTest extends TestCase {
6+
7+
public void testIsJava1IsAlwaysFalse() {
8+
assertFalse(Loader.isJava1());
9+
}
10+
}

0 commit comments

Comments
 (0)