88fantasy opened a new issue, #4489: URL: https://github.com/apache/streampark/issues/4489
### Search before asking - [X] I had searched in the [issues](https://github.com/apache/streampark/issues?q=is%3Aissue+label%3A%22bug%22) and found no similar issues referencing `ClassLoaderUtils` / `runAsClassLoader`. ### Java Version Temurin 21.0.11 (console), built with Microsoft OpenJDK 11.0.28 ### Scala Version 2.12.x ### StreamPark Version 3.0.0-SNAPSHOT (`dev` branch, commit `9ddda84c9`) ### Flink Version 1.20.4 and 2.2.1 (official binary distributions, standalone/remote cluster) ### Deploy mode remote ### What happened `ClassLoaderUtils.runAsClassLoader(target, supplier)` is meant to run a block under a given classloader and then put the calling thread back the way it found it. It does not: the `finally` restores `ORIGINAL_CLASS_LOADER`, a `static final` field initialised to `Thread.currentThread().getContextClassLoader()` **at class-initialisation time** — i.e. the context classloader of whichever thread first touched this class. ```java private static final ClassLoader ORIGINAL_CLASS_LOADER = Thread.currentThread().getContextClassLoader(); public static <R> R runAsClassLoader(ClassLoader targetClassLoader, Supplier<R> supplier) { try { Thread.currentThread().setContextClassLoader(targetClassLoader); return supplier.get(); } finally { Thread.currentThread().setContextClassLoader(ORIGINAL_CLASS_LOADER); // <-- not the caller's } } ``` The method is called from shared thread-pool threads, so for any caller whose context classloader was not that same value on entry, the "restore" silently installs a *different* classloader on that thread and leaves it there. Nothing fails at the call site; the damage lands on whatever runs on that pooled thread next. The correct behaviour is to capture the calling thread's own value on entry and restore that. `ORIGINAL_CLASS_LOADER` is still needed by `cloneClassLoader()` and stays. This is not a regression from the recent Scala-to-Java migration — `git log -p` shows the Scala version had the same shape. ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- 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]
