From 0262be6e21647b2beade1180705e52c1e3cee87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yoann=20Rodi=C3=A8re?= Date: Mon, 13 Jan 2025 16:00:41 +0100 Subject: [PATCH] Don't load JDBC drivers through the service loader without using them This was introduced in https://github.com/quarkusio/quarkus/pull/7089, which was specifically about a bug when using opentracing, which no longer has an extension in core, and even its Quarkiverse extension is no longer maintained: https://github.com/quarkiverse/quarkus-smallrye-opentracing The bug was also specific to Java 8. The service loading is also causing problems with https://github.com/quarkusio/quarkus/issues/41995 So, let's not do it all, assuming tests passes. --- .../quarkus/agroal/runtime/DataSources.java | 23 ------------------- 1 file changed, 23 deletions(-) diff --git a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java index eb719e72ac136..b8dd019dbe556 100644 --- a/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java +++ b/extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java @@ -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; @@ -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; @@ -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 drivers = ServiceLoader.load(Driver.class); - final Iterator iterator = drivers.iterator(); - while (iterator.hasNext()) { - try { - // load the driver - iterator.next(); - } catch (Throwable t) { - // ignore - } - } - } }