spuru9 commented on code in PR #29120:
URL: https://github.com/apache/flink/pull/29120#discussion_r3948236113
##########
flink-core/src/test/java/org/apache/flink/util/MdcLogbackCompatibilityTest.java:
##########
@@ -67,13 +66,13 @@ void testContextRestorationWorksWithNullContext() {
}
private MDCAdapter getCurrentMDCAdapter() throws Exception {
- Field adapterField = MDC.class.getDeclaredField("mdcAdapter");
+ Field adapterField = MDC.class.getDeclaredField("MDC_ADAPTER");
adapterField.setAccessible(true);
return (MDCAdapter) adapterField.get(null);
}
Review Comment:
Retracting this suggestion, sorry for the noise. I decompiled
`MDC.getMDCAdapter()` in 2.0.x and it's not a plain field read:
```
getstatic MDC_ADAPTER
ifnonnull -> return it
invokestatic getMDCAdapterGivenByProvider() // calls
LoggerFactory.getProvider(), logs ERROR
// if none found, falls back
to NOPMDCAdapter
putstatic MDC_ADAPTER // caches the fallback back
into the static field
getstatic MDC_ADAPTER
```
If `MDC_ADAPTER` is still null when the test runs (plausible here, since
flink-core doesn't bundle a real logging backend in test scope per the class
javadoc), calling the public getter instead of reading the field directly would
trigger a provider lookup, emit spurious ERROR-level log lines, and permanently
cache a NOPMDCAdapter into the static field for the rest of the test JVM. The
raw reflection read this PR already has avoids all of that, so it should stay
as-is.
##########
flink-core/src/test/java/org/apache/flink/util/MdcLogbackCompatibilityTest.java:
##########
@@ -67,13 +66,13 @@ void testContextRestorationWorksWithNullContext() {
}
private MDCAdapter getCurrentMDCAdapter() throws Exception {
- Field adapterField = MDC.class.getDeclaredField("mdcAdapter");
+ Field adapterField = MDC.class.getDeclaredField("MDC_ADAPTER");
adapterField.setAccessible(true);
return (MDCAdapter) adapterField.get(null);
}
Review Comment:
nit: since you're already touching this line for the field rename -
`MDC.getMDCAdapter()` is public on both 1.7.36 and 2.0.19 (checked via javap),
so the reflection here isn't needed for the getter, only for `setMDCAdapter`
(which stays package-private).
```suggestion
private MDCAdapter getCurrentMDCAdapter() throws Exception {
return MDC.getMDCAdapter();
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]