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
ClassNotFoundException using SQLExceptionOverride #2124
Labels
Comments
If someone provides a pull request with a fix and a unit test, I will be happy to merge it. |
quaff
added a commit
to quaff/HikariCP
that referenced
this issue
Nov 3, 2023
…loaded Before this commit, exceptionOverrideClass may be loaded by different ClassLoader, and two instances are created but only the latter one is used. This commit make sure the class will only loaded once and only one instance is created. Fix brettwooldridgeGH-2124
quaff
added a commit
to quaff/HikariCP
that referenced
this issue
Nov 6, 2023
…loaded Before this commit, exceptionOverrideClass may be loaded by different ClassLoader, and two instances are created but only the latter one is used. This commit make sure the class will only loaded once and only one instance is created. Fix brettwooldridgeGH-2124
quaff
added a commit
to quaff/HikariCP
that referenced
this issue
Feb 20, 2024
…loaded Before this commit, exceptionOverrideClass may be loaded by different ClassLoader, and two instances are created but only the latter one is used. This commit make sure the class will only loaded once and only one instance is created. Fix brettwooldridgeGH-2124 Fix brettwooldridgeGH-2171
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We run into a similar issue to #1489 so we were using the
SQLExceptionOverride
mechanism to avoid the eviction of a connection in some circumstancesBut in some scenarios a
ClassNotFoundException
is thrown when creating aHikariDataSource
after having defined a validHikariConfig
setting anexceptionOverrrideClassName
When the class name of the override handler is set via
HikariConfig.setExceptionOverrideClassName
to validate the input aloadClass
is attempted using the Thread Context ClassLoader. (HikariConfig
line 875)When this validated configuration is used to create a DataSource, and the
PoolBase
is instantiated, it attemps to load the class name for theexceptionOverrride
field, using theUtilityElf.createInstance(...)
method.But the
UtilityElf
doesn't use the Thread Context ClassLoader, but the ClassLoader used to load itself (UtilityElf
line 93):When the HikariCP library is at a higher class loader, like a application container ClassLoader, and the application using it is at "lower" class loader, like a typical WebApp ClassLoader for a WAR, it's not possible to use an application class as
SQLExceptionOverride
.Setting the className in the
HikariCofig
will work, because to check the validity of the className it uses the Thread Context Class Loader, but after that the instantiation ofPoolBase
will failIMO the solution should be change
UtilityElf
line 93 for:In case this isn't possible, for whatever reason, then the check on
HikariConfig.setExceptionOverrideClassName
line 875should be changed, to attempt a load from the class loader obtained using
HikariConfig.class.getClassLoader()
for example, so at least the behaviour is consistent, and you would get aClassNotFoundException
when creating theHikariConfig
The text was updated successfully, but these errors were encountered: