Skip to content

Commit 943fd34

Browse files
committed
Merge branch '3.4.x'
Closes gh-45992
2 parents 28c095c + 0f4e7ba commit 943fd34

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,9 @@ private V convertFromString(String value) {
508508
}
509509

510510
private String convertToString(V value) {
511+
if (value == null) {
512+
return null;
513+
}
511514
if (String.class.equals(this.type)) {
512515
return (String) value;
513516
}
@@ -712,7 +715,8 @@ private static class SimpleDataSourceProperties extends MappedDataSourceProperti
712715
@SuppressWarnings("unchecked")
713716
SimpleDataSourceProperties() {
714717
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
715-
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),
718+
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class,
719+
(dataSource) -> (dataSource.getDriver() != null) ? dataSource.getDriver().getClass() : null,
716720
SimpleDriverDataSource::setDriverClass);
717721
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
718722
add(DataSourceProperty.PASSWORD, SimpleDriverDataSource::getPassword, SimpleDriverDataSource::setPassword);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,16 @@ void buildWhenDerivedFromOracleUcpWithPasswordNotSetThrowsException() throws Exc
358358
.isThrownBy(() -> DataSourceBuilder.derivedFrom(dataSource).url("example.org").build());
359359
}
360360

361+
@Test
362+
void buildWhenDerivedFromSimpleDriverDataSourceAndDriverNotSetBuilds() {
363+
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
364+
dataSource.setUsername("test");
365+
dataSource.setPassword("secret");
366+
dataSource.setUrl("jdbc:postgresql://localhost:5432/postgres");
367+
assertThatNoException()
368+
.isThrownBy(() -> DataSourceBuilder.derivedFrom(dataSource).type(SimpleDriverDataSource.class).build());
369+
}
370+
361371
@Test
362372
void buildWhenDerivedFromOracleDataSourceWithPasswordSetReturnsDataSource() throws Exception {
363373
oracle.jdbc.datasource.impl.OracleDataSource dataSource = new oracle.jdbc.datasource.impl.OracleDataSource();

0 commit comments

Comments
 (0)