Skip to content

Commit 1f031f5

Browse files
committed
Polish "Avoid NPE in SimpleDataSourceProperties when driver is null"
See gh-45976
1 parent 1cf0d4e commit 1f031f5

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ private static class SimpleDataSourceProperties extends MappedDataSourceProperti
709709
SimpleDataSourceProperties() {
710710
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
711711
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class,
712-
(dataSource) -> dataSource.getDriver() == null ? null : dataSource.getDriver().getClass(),
712+
(dataSource) -> (dataSource.getDriver() != null) ? dataSource.getDriver().getClass() : null,
713713
SimpleDriverDataSource::setDriverClass);
714714
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
715715
add(DataSourceProperty.PASSWORD, SimpleDriverDataSource::getPassword, SimpleDriverDataSource::setPassword);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void buildWhenDerivedFromOracleUcpWithPasswordNotSetThrowsException() throws Exc
358358
}
359359

360360
@Test
361-
void buildWhenDerivedFromSimpleDriverDataSourceWithDriverNotSetSucceeds() throws Exception {
361+
void buildWhenDerivedFromSimpleDriverDataSourceAndDriverNotSetBuilds() {
362362
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
363363
dataSource.setUsername("test");
364364
dataSource.setPassword("secret");

0 commit comments

Comments
 (0)