[KYUUBI #7733][UTIL] Fall back to ReflectUtils's own loader when the context loader is null - #7734
Open
LuciferYang wants to merge 2 commits into
Open
Conversation
… class fails to link or initialize
…n the context loader is null
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why are the changes needed?
Closes #7733.
Stacked on #7724; its commit is the first of the two here, and the diff reduces to the second commit once #7724 merges.
ReflectUtils.isClassLoadabledefaults its loader to the thread context classloader. On a thread whose context loader is null,DynClasses.builder().loader(null)resolves the name throughClass.forName(name, true, null), which delegates to the bootstrap loader. The bootstrap loader sees only JDK classes, so the probe answersfalsefor every application class, including Kyuubi's own, even when it is loadable through the loader that definedReflectUtils.This falls back to
ReflectUtils's own classloader when the effective loader is null, matching Spark'sgetContextOrSparkClassLoader. The change is monotonic: a non-null loader behaves exactly as before, and a null loader can only turn afalseinto atrue(an application class becomes loadable), never the reverse. Repository threads carry a non-null context loader under normal startup, so this is defensive hardening for embedded hosts (a JNI invocation that never sets a context loader, a container framework that clears it) and third-party callers of this public helper.How was this patch tested?
Added a
ReflectUtilsSuitecase that sets the thread context loader to null (restored infinally) and asserts an application class is loadable while a non-existent one is not. It fails without the fallback, since the bootstrap loader cannot see the class.Module green on Zulu 17.0.18 (23/23), scalastyle 0 errors, spotless clean.
Was this patch assisted by generative AI tooling?
Assisted-by: Claude Opus 4.8