Skip to content
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

Don't load JDBC drivers through the service loader without using them #45540

Merged
merged 1 commit into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package io.quarkus.agroal.runtime;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.Statement;
import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;

Expand Down Expand Up @@ -157,9 +154,6 @@ public AgroalDataSource createDataSource(String dataSourceName) {
"Datasource " + dataSourceName + " does not have a JDBC URL and should not be created");
}

// we first make sure that all available JDBC drivers are loaded in the current TCCL
loadDriversInTCCL();

AgroalDataSourceSupport.Entry matchingSupportEntry = agroalDataSourceSupport.entries.get(dataSourceName);
String resolvedDriverClass = matchingSupportEntry.resolvedDriverClass;
Class<?> driver;
Expand Down Expand Up @@ -354,21 +348,4 @@ public boolean isValid(Connection connection) {
poolConfiguration.flushOnClose(dataSourceJdbcRuntimeConfig.flushOnClose());
}

/**
* Uses the {@link ServiceLoader#load(Class) ServiceLoader to load the JDBC drivers} in context
* of the current {@link Thread#getContextClassLoader() TCCL}
*/
private static void loadDriversInTCCL() {
// load JDBC drivers in the current TCCL
final ServiceLoader<Driver> drivers = ServiceLoader.load(Driver.class);
final Iterator<Driver> iterator = drivers.iterator();
while (iterator.hasNext()) {
try {
// load the driver
iterator.next();
} catch (Throwable t) {
// ignore
}
}
}
}
Loading