Skip to content

Fix the SingleConnectionDataSource constructor to allow null url, username, password#36645

Open
dbyron-sf wants to merge 1 commit intospring-projects:mainfrom
dbyron-sf:singleConnectionDataSource-nullable-constructor-args
Open

Fix the SingleConnectionDataSource constructor to allow null url, username, password#36645
dbyron-sf wants to merge 1 commit intospring-projects:mainfrom
dbyron-sf:singleConnectionDataSource-nullable-constructor-args

Conversation

@dbyron-sf
Copy link
Copy Markdown

@dbyron-sf dbyron-sf commented Apr 12, 2026

since the underlying AbstractDriverBasedDataSource.setUrl, setUsername and setPassword methods allow null.

The @NonNullFields annotation in
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java requires null without an explicit @Nullable annotation.

…rname, password

since the underlying AbstractDriverBasedDataSource.setUrl, setUsername and setPassword
methods allow null.

The @NonNullFields annotation in
spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java requires
null without an explicit @nullable annotation.

Signed-off-by: David Byron <dbyron@salesforce.com>
@dbyron-sf dbyron-sf force-pushed the singleConnectionDataSource-nullable-constructor-args branch from cad7da0 to 0c2f49e Compare April 12, 2026 00:35
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 12, 2026
dbyron-sf added a commit to dbyron-sf/spinnaker that referenced this pull request Apr 12, 2026
…createDataSource

```
$ ./gradlew :kork:kork-sql:compileKotlin
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:75:43
   Type mismatch: inferred type is String? but String was expected
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:75:52
   Type mismatch: inferred type is String? but String was expected
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:75:58
   Type mismatch: inferred type is String? but String was expected
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:77:31
   Type mismatch: inferred type is String? but String was expected
```
It's straightforward to remove the warning related to driver.  For the others,
SingleConnectionDataSource constructor params are marked non-null by the package-level
@NonNullApi annotation in
https://github.com/spring-projects/spring-framework/blob/v6.0.21/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java,
but the constructor delegates to @nullable setters and null is valid at runtime.  See
spring-projects/spring-framework#36645.
dbyron-sf added a commit to spinnaker/spinnaker that referenced this pull request Apr 13, 2026
* fix(kork/sql): replace deprecated DefaultExecuteListener with ExecuteListener interface

to fix:
```
$ ./gradlew kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/JooqSqlCommentAppender.kt:20:22 'DefaultExecuteListener' is deprecated. Deprecated in Java
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/JooqSqlCommentAppender.kt:27:32 'DefaultExecuteListener' is deprecated. Deprecated in Java
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/JooqToSpringExceptionTransformer.kt:19:22 'DefaultExecuteListener' is deprecated. Deprecated in Java
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/JooqToSpringExceptionTransformer.kt:26:42 'DefaultExecuteListener' is deprecated. Deprecated in Java
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/telemetry/JooqSlowQueryLogger.kt:20:22 'DefaultExecuteListener' is deprecated. Deprecated in Java
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/telemetry/JooqSlowQueryLogger.kt:29:5 'DefaultExecuteListener' is deprecated. Deprecated in Java
```
DefaultExecuteListener was deprecated in jOOQ 3.15. Since jOOQ 3.15+
the ExecuteListener interface provides default method implementations,
so classes can implement it directly.

* fix(kork/sql): replace deprecated toLowerCase() with lowercase()

```
$ ./gradlew kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/routing/NamedDatabaseContextHolder.kt:26:22 'toLowerCase(): String' is deprecated. Use lowercase() instead.
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/DefaultSqlConfiguration.kt:127:44 'toLowerCase(): String' is deprecated. Use lowercase() instead.
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/routing/NamedDatabaseContextHolder.kt:26:22 'toLowerCase(): String' is deprecated. Use lowercase() instead.
```
String.toLowerCase() was deprecated in Kotlin 1.5 in favor of
lowercase().

* fix(kork/sql): remove always-true null check on dialect() in JooqToSpringExceptionTransformer

to remove this warning:
```
$ ./gradlew :kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/JooqToSpringExceptionTransformer.kt:31:28 Condition 'dialect != null' is always 'true'
```
Configuration.dialect() returns non-null SQLDialect (defaults to SQLDialect.DEFAULT), so
the null branch was dead code.

* fix(kork/sql): fix SQLException? type mismatch in JooqToSpringExceptionTransformer

to remove this warning:
```
$ ./gradlew :kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/JooqToSpringExceptionTransformer.kt:36:61 Type mismatch: inferred type is SQLException? but SQLException was expected
```
Use early-return with ?: to smart-cast sqlException() to non-null,
avoiding the second nullable call to ctx.sqlException() inside the
if block.

* fix(kork/sql): remove type mismatch warnings in SpringLiquibaseProxy.createDataSource

```
$ ./gradlew :kork:kork-sql:compileKotlin
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:75:43
   Type mismatch: inferred type is String? but String was expected
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:75:52
   Type mismatch: inferred type is String? but String was expected
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:75:58
   Type mismatch: inferred type is String? but String was expected
w: ...kork/sql/migration/SpringLiquibaseProxy.kt:77:31
   Type mismatch: inferred type is String? but String was expected
```
It's straightforward to remove the warning related to driver.  For the others,
SingleConnectionDataSource constructor params are marked non-null by the package-level
@NonNullApi annotation in
https://github.com/spring-projects/spring-framework/blob/v6.0.21/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/package-info.java,
but the constructor delegates to @nullable setters and null is valid at runtime.  See
spring-projects/spring-framework#36645.

* fix(kork/sql): suppress connectionPool deprecation warning in DefaultSqlConfiguration.dataSource

```
$ ./gradlew :kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/DefaultSqlConfiguration.kt:85:63 'connectionPool: ConnectionPoolProperties?' is deprecated. use named connection pools instead
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/DefaultSqlConfiguration.kt:90:22 'connectionPool: ConnectionPoolProperties?' is deprecated. use named connection pools instead
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/DefaultSqlConfiguration.kt:94:60 'connectionPool: ConnectionPoolProperties?' is deprecated. use named connection pools instead
```
The dataSource method intentionally references the deprecated SqlProperties.connectionPool
for backwards compatibility. Suppress the warning until connectionPool is removed.

* fix(kork/sql): suppress connectionPool deprecation warning in SqlProperties.getDefaultConnectionPoolProperties

```
$ ./gradlew :kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/SqlProperties.kt:61:11 'connectionPool: ConnectionPoolProperties?' is deprecated. use named connection pools instead
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/SqlProperties.kt:64:14 'connectionPool: ConnectionPoolProperties?' is deprecated. use named connection pools instead
```
The method intentionally references the deprecated connectionPool for backwards
compatibility. Suppress the warning until connectionPool is removed.

* fix(kork/sql): suppress unchecked cast warning in DefaultSqlConfiguration.dataSource

```
$ ./gradlew :kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/config/DefaultSqlConfiguration.kt:129:49 Unchecked cast: Map<String, DataSource> to Map<Any, Any>
```
The cast is safe at runtime due to erasure but unavoidable without copying the map, since
Kotlins Map is invariant in its key type.

* fix(kork/sql): fix nullability mismatch in StaticDataSourceLookup.getDataSource

to remove this warning:
```
$ ./gradlew :kork:kork-sql:compileKotlin
w: file:///Users/dbyron/src/spinnaker/spinnaker/kork/kork-sql/src/main/kotlin/com/netflix/spinnaker/kork/sql/routing/StaticDataSourceLookup.kt:31:3 Override 'fun getDataSource(dataSourceName: String): DataSource?' has incorrect nullability in its signature comparing with overridden 'fun getDataSource(dataSourceName: String): DataSource'
```
Match the Java interface return type (non-null DataSource) and throw
DataSourceLookupFailureException on missing name, consistent with the Spring
DataSourceLookup contract.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants