Fix GH-2147 by adding an extra check to make sure we don't remove the wrong driver from the DriverManager (#2148)

Fixes #2147
This commit is contained in:
Henri S 2021-11-07 08:52:25 +02:00 committed by GitHub
parent fe0adf55ca
commit b680bc099a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -153,7 +153,9 @@ public class MySQLDB extends SQLDB {
Enumeration<Driver> drivers = DriverManager.getDrivers();
while (drivers.hasMoreElements()) {
Driver driver = drivers.nextElement();
if ("com.mysql.cj.jdbc.Driver".equals(driver.getClass().getName())) {
Class<?> driverClass = driver.getClass();
// Checks that it's from our class loader to avoid unloading another plugin's/the server's driver
if ("com.mysql.cj.jdbc.Driver".equals(driverClass.getName()) && driverClass.getClassLoader() == driverClassLoader) {
try {
DriverManager.deregisterDriver(driver);
} catch (SQLException e) {