<div dir="ltr"><div>Hello!</div><div><br></div><div>I've been looking for a concrete explanation for why the JDBC DriverManager can't find drivers under the following circumstances:</div><div><br></div><div>* Driver jar loaded into child classloader of app classloader</div><div>* Child classloader set for current thread's context classloader</div><div><br></div><div>My long explanation of the issue is here:</div><div><br></div><div><a href="https://github.com/jruby/jruby/issues/8910#issuecomment-3453029437">https://github.com/jruby/jruby/issues/8910#issuecomment-3453029437</a></div><div><br></div><div>The short explanation is that when the DriverManager goes to check for "allowed" drivers, it ends up using the wrong classloader.</div><div><br></div><div><a href="https://github.com/openjdk/jdk/blob/8151251fa683459e57430abf8e3583c444315746/src/java.sql/share/classes/java/sql/DriverManager.java#L157">https://github.com/openjdk/jdk/blob/8151251fa683459e57430abf8e3583c444315746/src/java.sql/share/classes/java/sql/DriverManager.java#L157</a></div><div><br></div><div>* Caller's class is acquired with Reflection.getCallerClass</div><div>* Caller's classloader is acquired</div><div>* If that classloader is null, as it would have been for classes loaded on the root classpath in Java 8, it instead uses the thread context classloader.</div><div>* If that classloader is not null (Java 9+) and not the platform classloader, it is used for verification; in this case it is the system classloader (a "ClassLoader#AppClassLoader" instance) so the child classloader's driver is disallowed.</div><div><br></div><div>My confusion is why this code was never patched for the change to the system classloader (from null to an AppClassLoader). The logic in DriverManager will never use the ThreadContext classloader now, since there's almost no cases where "getClassLoader" will return null.</div><div><br></div><div>Is there a good explanation for why this code still checks for a null classloader?</div><div><br></div><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><b>Charles Oliver Nutter</b><div><i>Architect and Technologist</i></div><div>Headius Enterprises</div><a href="https://www.headius.com" target="_blank">https://www.headius.com</a><div><div><a href="mailto:headius@headius.com" target="_blank">headius@headius.com</a></div></div></div></div></div></div>