Skip to content

fix: SqlCapture captures an action that returns no row - #490

Merged
zantvoort merged 1 commit into
mainfrom
fix/sql-capture-nullable-result
Aug 12, 2026
Merged

fix: SqlCapture captures an action that returns no row#490
zantvoort merged 1 commit into
mainfrom
fix/sql-capture-nullable-result

Conversation

@zantvoort

Copy link
Copy Markdown
Collaborator

SqlCapture.execute and executeThrowing declared a bare <T> in a @NullMarked package, so Kotlin reads the result type as T : Any. A capture whose action ends in a lookup that finds nothing — the ordinary case in a test — does not compile:

val genre = capture.execute { genreRepository.findByName("Sci-Fi") }
// Cannot infer type for type parameter 'T'. Specify it explicitly.
// Return type mismatch: expected 'Any', actual 'Genre?'.

Both now declare T extends @Nullable Object, the treatment the rest of the null-marked surface already gives a type parameter that admits a nullable argument (TypedMetamodel, AbstractMetamodel, Instantiator, Metamodel.getValue). The 1.14.0 changelog entry that lists those is extended with these two.

There is no workaround worth having on the caller's side: capturing a nullable lookup means declaring a var ahead of the block and assigning into it from record { }, which is exactly the shape execute exists to avoid.

Why it was not caught

Two gaps line up. Strict JSpecify enforcement starts at Kotlin 2.1, which the reactor's own Kotlin 2.0 modules never exercise, and storm-test's own tests are written in Java, where a non-null type parameter compiles regardless of the annotation. So the Kotlin 2.4 smoke projects — the surface the changelog already names as the guard for this — gain a case that compiles both calls against a nullable-returning action.

The guard was verified in both directions: it fails against a storm-test built without the fix, with the same diagnostic quoted above, and passes with it.

Notes

SqlInterceptorManager.Scope.get / call carry the same bare <T> one level down. They are internal and reached only from Java today, so they are left alone; a Kotlin caller inside Storm would hit the same wall.

Found while migrating the five storm-example-* repositories to 1.14.0, where capture.execute { … } on a nullable repository lookup stopped compiling.

The result type of execute and executeThrowing was a bare <T> in a
@NullMarked package, so Kotlin read it as T : Any and a capture whose
action ends in a lookup that finds nothing did not compile:

    val genre = capture.execute { genreRepository.findByName("Sci-Fi") }

Both now declare T extends @nullable Object, the treatment the rest of
the null-marked surface already gives a type parameter that admits a
nullable argument.

Strict JSpecify enforcement starts at Kotlin 2.1, which the reactor's
own Kotlin 2.0 modules never exercise, and storm-test's tests are
written in Java, where a non-null type parameter compiles regardless,
so the Kotlin 2.4 smoke projects gain a case that compiles both calls.
@zantvoort
zantvoort merged commit a5604f5 into main Aug 12, 2026
8 checks passed
@zantvoort
zantvoort deleted the fix/sql-capture-nullable-result branch August 12, 2026 14:47
@codecov

codecov Bot commented Aug 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant