Replacing log4j with reload4j can cause NoSuchFieldError
See original GitHub issueThis appears to be an interaction between certain versions of the slf4j-log4j12 library and reload4j. If reload4j is used instead of log4j, then using MDC will cause the following stack trace:
Exception in thread "main" java.lang.NoSuchFieldError: tlm
at org.apache.log4j.MDCFriend.fixForJava9(MDCFriend.java:11)
at org.slf4j.impl.Log4jMDCAdapter.<clinit>(Log4jMDCAdapter.java:38)
at Main.main(Main.java:5)
This was discovered by trying to replace log4j with reload4j in the apache Kafka repository, https://github.com/apache/kafka/blob/6eed7743ff6c0e73d65c09bac2e2ad9586cc56ce/gradle/dependencies.gradle#L174
It only occurs in Java versions above 8. The minimal reproduction can be found here: https://github.com/scott-kirk/reload4j-exception I know it’s slf4j code that’s directly causing this, and it is fixed by upgrading slf4j to the latest version, I was just caught off guard by this issue and think it’d be useful to either explicitly say to use the latest version of slf4j or to somehow apply a workaround to avoid needing to also upgrade slf4j.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)
SLF4J documentation updated to explain the problem.
See https://www.slf4j.org/codes.html#no_tlm
@ceki As you indicated in your last message, this backward compatibility problem was fixed in commits https://github.com/qos-ch/reload4j/commit/0cbed4256a40a9e30e2157997cd137fae50f4c57 and https://github.com/qos-ch/reload4j/commit/dc3cc1f245c0cab397ccdf0bf2a416b53b9cee98 . Version 1.2.21 including those commit has been released.
Therefore, I think this issue can be closed. Correct ?