Skip to content

Commit 05fe8ea

Browse files
committed
Fix NPE in SimpleDataSourceProperties when driver is null
- Prevent NullPointerException in SimpleDataSourceProperties by adding null check before calling getDriver().getClass(). - Fixes potential crash when driver is not explicitly configured. Signed-off-by: chanbinme <gksmfcksqls@gmail.com>
1 parent 1ae0548 commit 05fe8ea

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,8 @@ private static class SimpleDataSourceProperties extends MappedDataSourceProperti
712712
@SuppressWarnings("unchecked")
713713
SimpleDataSourceProperties() {
714714
add(DataSourceProperty.URL, SimpleDriverDataSource::getUrl, SimpleDriverDataSource::setUrl);
715-
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class, (dataSource) -> dataSource.getDriver().getClass(),
715+
add(DataSourceProperty.DRIVER_CLASS_NAME, Class.class,
716+
(dataSource) -> dataSource.getDriver() == null ? null : dataSource.getDriver().getClass(),
716717
SimpleDriverDataSource::setDriverClass);
717718
add(DataSourceProperty.USERNAME, SimpleDriverDataSource::getUsername, SimpleDriverDataSource::setUsername);
718719
add(DataSourceProperty.PASSWORD, SimpleDriverDataSource::getPassword, SimpleDriverDataSource::setPassword);

0 commit comments

Comments
 (0)