-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replacing log4j with reload4j can cause NoSuchFieldError #41
Comments
Thank you for this detailed report. The following analysis is inaccurate and should not be heeded. It is preserved here for the historical record.
Thus, the issue is not caused by relaod4j but by slf4j-log4j12 trying to fix log4j's MDC and failing to do so due to new JDK reflection restrictions. |
Thanks for the response and the explanation. The link you provided is useful, but could you elaborate on This could be just an interaction with the specific versions I'm using, but I just want to make sure we're on the same page |
You are right. Thank you for following up on this. When I create the classpath manually, the observe behaviors are indeed different when run with log4j.jar and reload4j.jar. Now that I think of it, this actually makes sense, since the type of MDC package private field
No, mystery solved as explained above. I'll update the docs again (tomorrow). |
SLF4J documentation updated to explain the problem. |
* Replace `log4j` with `reload4j` in `copyDependantLibs`. Since we have some projects that have an explicit `reload4j` dependency, it was included in the final release release tar - i.e. it was effectively a workaround for this bug. * Exclude `log4j` and `slf4j-log4j12` transitive dependencies for `streams:upgrade-system-tests`. Versions 0100 and 0101 had a transitive dependency to `log4j` and `slf4j-log4j12` via `zkclient` and `zookeeper`. This avoids classpath conflicts that lead to [NoSuchFieldError](qos-ch/reload4j#41) in system tests. Reviewers: Jason Gustafson <jason@confluent.io>
* Replace `log4j` with `reload4j` in `copyDependantLibs`. Since we have some projects that have an explicit `reload4j` dependency, it was included in the final release release tar - i.e. it was effectively a workaround for this bug. * Exclude `log4j` and `slf4j-log4j12` transitive dependencies for `streams:upgrade-system-tests`. Versions 0100 and 0101 had a transitive dependency to `log4j` and `slf4j-log4j12` via `zkclient` and `zookeeper`. This avoids classpath conflicts that lead to [NoSuchFieldError](qos-ch/reload4j#41) in system tests. Reviewers: Jason Gustafson <jason@confluent.io>
* Replace `log4j` with `reload4j` in `copyDependantLibs`. Since we have some projects that have an explicit `reload4j` dependency, it was included in the final release release tar - i.e. it was effectively a workaround for this bug. * Exclude `log4j` and `slf4j-log4j12` transitive dependencies for `streams:upgrade-system-tests`. Versions 0100 and 0101 had a transitive dependency to `log4j` and `slf4j-log4j12` via `zkclient` and `zookeeper`. This avoids classpath conflicts that lead to [NoSuchFieldError](qos-ch/reload4j#41) in system tests. Reviewers: Jason Gustafson <jason@confluent.io>
* Replace `log4j` with `reload4j` in `copyDependantLibs`. Since we have some projects that have an explicit `reload4j` dependency, it was included in the final release release tar - i.e. it was effectively a workaround for this bug. * Exclude `log4j` and `slf4j-log4j12` transitive dependencies for `streams:upgrade-system-tests`. Versions 0100 and 0101 had a transitive dependency to `log4j` and `slf4j-log4j12` via `zkclient` and `zookeeper`. This avoids classpath conflicts that lead to [NoSuchFieldError](qos-ch/reload4j#41) in system tests. Reviewers: Jason Gustafson <jason@confluent.io>
This backward compatibility problem was fixed in commits 0cbed42 and dc3cc1f shipping with reload4j version 1.2.21.
|
reload4j is a drop-in replacement for log4j 1.2.17 The binary compatibility issue [0] between earlier versions of reload4j and slf4j-log4j12 has been fixed. Although it is recommended that you use slf4j-reload4j as the preferred adapter for the slf4j/reload4j combination, with reload4j version 1.2.21 and later you can freely mix any version of slf4j-log4j12, if you have to. From Docker: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/src/openseedbox/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/play/framework/lib/slf4j-log4j12-1.7.22.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory] [0]: qos-ch/reload4j#41
reload4j is a drop-in replacement for log4j 1.2.17 The binary compatibility issue [0] between earlier versions of reload4j and slf4j-log4j12 has been fixed. Although it is recommended that you use slf4j-reload4j as the preferred adapter for the slf4j/reload4j combination, with reload4j version 1.2.21 and later you can freely mix any version of slf4j-log4j12, if you have to. From Docker: SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/src/openseedbox-server/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/play/framework/lib/slf4j-log4j12-1.7.22.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.slf4j.impl.Reload4jLoggerFactory] [0]: qos-ch/reload4j#41
This 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:
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.
The text was updated successfully, but these errors were encountered: