MDC.clear() invoked in child class deletes parent keys

Hello, I found an issue using the MDC. I have a filter that does the following: .... MDC.put("key", value); filterChain.doFilter(request, response); value = MDC.get("key"); ... And the value is empty. The problem comes because a child controller class does: MDC.put("key2") ... some logic.... finally{ MDC.clear(); } And that call deletes all the content of the map. The problem is that the child class does not check if the MDC contains something. Of course this could be considered as a bad practice, but this "clear()" method is too risky as it deletes ALL, even the parent keys... I found this ticket : http://jira.qos.ch/browse/LOGBACK-325 <http://www.google.com/url?q=http%3A%2F%2Fjira.qos.ch%2Fbrowse%2FLOGBACK-325&sa=D&sntz=1&usg=AFQjCNG_Wg9OkA61aCyECP9CtxecviR4Vg> but it seems to be resolved. The version I'm using is the loback-classic 1.1.2 Let me know if you need more information. Thank you. Best Regards, Javier

Kuu wrote
MDC.put("key2") ... some logic.... finally{ MDC.clear(); }
I thought the normal way is to _only_ clear the key(s) you put in: ``` MDC.put("key2") ... some logic.... finally{ MDC.remove("key2"); } ``` -- View this message in context: http://logback.10977.n7.nabble.com/MDC-clear-invoked-in-child-class-deletes-... Sent from the Users mailing list archive at Nabble.com.

Hi Javier, Is the child controller in the same thread or a different thread? -- Ceki On 2/10/2016 11:21, Kuu wrote:
Hello,
I found an issue using the MDC. I have a filter that does the following:
.... MDC.put("key", value); filterChain.doFilter(request, response); value = MDC.get("key"); ...
And the value is empty.
The problem comes because a child controller class does:
MDC.put("key2") ... some logic.... finally{ MDC.clear(); }
And that call deletes all the content of the map. The problem is that the child class does not check if the MDC contains something. Of course this could be considered as a bad practice, but this "clear()" method is too risky as it deletes ALL, even the parent keys...
I found this ticket : http://jira.qos.ch/browse/LOGBACK-325 <http://www.google.com/url?q=http%3A%2F%2Fjira.qos.ch%2Fbrowse%2FLOGBACK-325&sa=D&sntz=1&usg=AFQjCNG_Wg9OkA61aCyECP9CtxecviR4Vg> but it seems to be resolved.
The version I'm using is the loback-classic 1.1.2
Let me know if you need more information. Thank you.
Best Regards, Javier
participants (3)
-
Ceki Gulcu
-
Kuu
-
yihtserns