Browse Source

Polish "Avoid NPE in SimpleDataSourceProperties when driver is null"

See gh-45976
3.3.x
Stéphane Nicoll 8 months ago
parent
commit
1f031f5fa6
  1. 2
      spring-boot-project/spring-boot/src/main/java/org/springframework/boot/jdbc/DataSourceBuilder.java
  2. 2
      spring-boot-project/spring-boot/src/test/java/org/springframework/boot/jdbc/DataSourceBuilderTests.java

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

@ -709,7 +709,7 @@ public final class DataSourceBuilder<T extends DataSource> { @@ -709,7 +709,7 @@ public final class DataSourceBuilder<T extends DataSource> {
SimpleDataSourceProperties() {
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class,
(dataSource) -> dataSource.getDriver() == null ? null : dataSource.getDriver().getClass(),
(dataSource) -> (dataSource.getDriver() != null) ? dataSource.getDriver().getClass() : null,
SimpleDriverDataSource::setDriverClass);
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
add(DataSourceProperty.PASSWORD, SimpleDriverDataSource::getPassword, SimpleDriverDataSource::setPassword);

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

@ -358,7 +358,7 @@ class DataSourceBuilderTests { @@ -358,7 +358,7 @@ class DataSourceBuilderTests {
}
@Test
void buildWhenDerivedFromSimpleDriverDataSourceWithDriverNotSetSucceeds() throws Exception {
void buildWhenDerivedFromSimpleDriverDataSourceAndDriverNotSetBuilds() {
SimpleDriverDataSource dataSource = new SimpleDriverDataSource();
dataSource.setUsername("test");
dataSource.setPassword("secret");

Loading…
Cancel
Save