Skip to content

Commit 0f4e7ba

Browse files
committed
Merge branch '3.3.x' into 3.4.x
Closes gh-45991
2 parents 8deffd2 + e914539 commit 0f4e7ba

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
@@ -513,6 +513,9 @@ private V convertFromString(String value) {
513513
}
514514

515515
private String convertToString(V value) {
516+
if (value == null) {
517+
return null;
518+
}
516519
if (String.class.equals(this.type)) {
517520
return (String) value;
518521
}
@@ -705,7 +708,8 @@ private static class SimpleDataSourceProperties extends MappedDataSourceProperti
705708
@SuppressWarnings("unchecked")
706709
SimpleDataSourceProperties() {
707710
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
708-
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),
711+
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class,
712+
(dataSource) -> (dataSource.getDriver() != null) ? dataSource.getDriver().getClass() : null,
709713
SimpleDriverDataSource::setDriverClass);
710714
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
711715
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
@@ -357,6 +357,16 @@ void buildWhenDerivedFromOracleUcpWithPasswordNotSetThrowsException() throws Exc
357357
.isThrownBy(() -> DataSourceBuilder.derivedFrom(dataSource).url("example.org").build());
358358
}
359359

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

0 commit comments

Comments
 (0)