From 1754018a7b5e772678be1aea76f0ad7c10aa4bf1 Mon Sep 17 00:00:00 2001 From: Moritz Halbritter Date: Fri, 16 Dec 2022 15:56:45 +0100 Subject: [PATCH] Polish DevToolsDataSourceAutoConfiguration --- .../DevToolsDataSourceAutoConfiguration.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java index 3321414228..4c363f0292 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java @@ -19,8 +19,6 @@ package org.springframework.boot.devtools.autoconfigure; import java.sql.Connection; import java.sql.SQLException; import java.sql.Statement; -import java.util.Arrays; -import java.util.HashSet; import java.util.Properties; import java.util.Set; @@ -108,8 +106,11 @@ public class DevToolsDataSourceAutoConfiguration { private enum InMemoryDatabase { - DERBY(null, new HashSet<>(Arrays.asList("org.apache.derby.jdbc.EmbeddedDriver")), (dataSource) -> { - String url = dataSource.getConnection().getMetaData().getURL(); + DERBY(null, Set.of("org.apache.derby.jdbc.EmbeddedDriver"), (dataSource) -> { + String url; + try (Connection connection = dataSource.getConnection()) { + url = connection.getMetaData().getURL(); + } try { new EmbeddedDriver().connect(url + ";drop=true", new Properties()).close(); } @@ -120,10 +121,10 @@ public class DevToolsDataSourceAutoConfiguration { } }), - H2("jdbc:h2:mem:", new HashSet<>(Arrays.asList("org.h2.Driver", "org.h2.jdbcx.JdbcDataSource"))), + H2("jdbc:h2:mem:", Set.of("org.h2.Driver", "org.h2.jdbcx.JdbcDataSource")), - HSQLDB("jdbc:hsqldb:mem:", new HashSet<>(Arrays.asList("org.hsqldb.jdbcDriver", - "org.hsqldb.jdbc.JDBCDriver", "org.hsqldb.jdbc.pool.JDBCXADataSource"))); + HSQLDB("jdbc:hsqldb:mem:", Set.of("org.hsqldb.jdbcDriver", "org.hsqldb.jdbc.JDBCDriver", + "org.hsqldb.jdbc.pool.JDBCXADataSource")); private final String urlPrefix;