View Javadoc

    1   package org.apache.log4j;
    2
    3   import java.lang.reflect.Field;
    4   import java.lang.reflect.Method;
    5
    6   import org.apache.log4j.helpers.ThreadLocalMap;
    7
    8   public class MDCFriend {
    9
    10  	public static void fixForJava9() {
    11  		if (MDC.mdc.tlm == null) {
    12  			MDC.mdc.tlm = new ThreadLocalMap();
    13  			MDC.mdc.java1 = false;
    14  			setRemoveMethod(MDC.mdc);
    15  		}
    16
    17  	}
    18
    19  	private static void setRemoveMethod(MDC mdc) {
    20  		try {
    21  			Method removeMethod = ThreadLocal.class.getMethod("remove");
    22  			Field removeMethodField = MDC.class.getDeclaredField("removeMethod");
    23  			removeMethodField.setAccessible(true);
    24  			removeMethodField.set(mdc, removeMethod);
    25  		} catch (NoSuchMethodException e) {
    26  		} catch (SecurityException e) {
    27  		} catch (NoSuchFieldException e) {
    28  		} catch (IllegalArgumentException e) {
    29  		} catch (IllegalAccessException e) {
    30  		}
    31
    32  	}
    33  }