Skip to content

[KYUUBI #7723][UTIL] Answer false from isClassLoadable when the class fails to link or initialize - #7724

Open
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:kyuubi-util-scala-classloadable-linkageerror
Open

[KYUUBI #7723][UTIL] Answer false from isClassLoadable when the class fails to link or initialize#7724
LuciferYang wants to merge 1 commit into
apache:masterfrom
LuciferYang:kyuubi-util-scala-classloadable-linkageerror

Conversation

@LuciferYang

Copy link
Copy Markdown
Contributor

Why are the changes needed?

Closes #7723.

ReflectUtils.isClassLoadable wrapped its DynClasses probe in scala.util.Try, which catches only NonFatal. The probe resolves the name with Class.forName(className, true, loader), so a class that is present but fails to link or initialize raises a LinkageError (NoClassDefFoundError, ExceptionInInitializerError) rather than a ClassNotFoundException. LinkageError is not NonFatal, so it escaped the probe and crashed the caller instead of answering false.

This replaces the Try with an explicit try/catch that answers false on ClassNotFoundException and LinkageError. The two call sites (Logging probing the SLF4J bridge, JDBCMetadataStore probing the MySQL driver) read the result as a boolean and are only made safer. OutOfMemoryError/StackOverflowError are VirtualMachineError, not LinkageError, so they stay fatal exactly as they did under Try.

How was this patch tested?

Added a ReflectUtilsSuite case that probes a top-level object whose static initializer throws, by its binary name, and asserts isClassLoadable returns false. Reverting the production change makes the suite abort as the ExceptionInInitializerError escapes, which pins the regression.

build/mvn test -pl kyuubi-util-scala -am
build/mvn scalastyle:check spotless:check -pl kyuubi-util-scala -am

Module green on Zulu 17.0.18 (22/22), scalastyle 0 errors, spotless clean.

Was this patch assisted by generative AI tooling?

Assisted-by: Claude Opus 4.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReflectUtils.isClassLoadable throws LinkageError instead of answering false for classes that fail to link or initialize

2 participants