Skip to content

Commit 219c7ed

Browse files
committed
Merge branch '3.4.x'
Closes gh-44999
2 parents c179fed + e107e11 commit 219c7ed

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/HikariJdbcConnectionDetailsBeanPostProcessor.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,10 @@ protected Object processDataSource(HikariDataSource dataSource, JdbcConnectionDe
3939
dataSource.setJdbcUrl(connectionDetails.getJdbcUrl());
4040
dataSource.setUsername(connectionDetails.getUsername());
4141
dataSource.setPassword(connectionDetails.getPassword());
42-
dataSource.setDriverClassName(connectionDetails.getDriverClassName());
42+
String driverClassName = connectionDetails.getDriverClassName();
43+
if (driverClassName != null) {
44+
dataSource.setDriverClassName(connectionDetails.getDriverClassName());
45+
}
4346
return dataSource;
4447
}
4548

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/jdbc/HikariJdbcConnectionDetailsBeanPostProcessorTests.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2023 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
2222
import org.springframework.boot.jdbc.DatabaseDriver;
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
25+
import static org.mockito.Mockito.mock;
2526

2627
/**
2728
* Tests for {@link HikariJdbcConnectionDetailsBeanPostProcessor}.
@@ -47,4 +48,13 @@ void setUsernamePasswordAndUrl() {
4748
assertThat(dataSource.getDriverClassName()).isEqualTo(DatabaseDriver.POSTGRESQL.getDriverClassName());
4849
}
4950

51+
@Test
52+
void toleratesConnectionDetailsWithNullDriverClassName() {
53+
HikariDataSource dataSource = new HikariDataSource();
54+
dataSource.setDriverClassName(DatabaseDriver.H2.getDriverClassName());
55+
JdbcConnectionDetails connectionDetails = mock(JdbcConnectionDetails.class);
56+
new HikariJdbcConnectionDetailsBeanPostProcessor(null).processDataSource(dataSource, connectionDetails);
57+
assertThat(dataSource.getDriverClassName()).isEqualTo(DatabaseDriver.H2.getDriverClassName());
58+
}
59+
5060
}

0 commit comments

Comments
 (0)