jspecify / jspecify/jspecify

Kotlin backwards compatibility for annotated Java libraries

Open
#723 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
1.1k
Forks
43
Avg merge
9m
Merged PRs (30d)
13

Description

I noticed this interesting compilation error on a kotlin wrapper for Caffeine when it attempted to upgrade the dependency to the JSpecify annotated version. Here's a cleaned up error message for their CoroutineAsyncCacheLoader.

CoroutineAsyncCacheLoaders.kt:26:8 
    Return type of 'asyncLoad' is not a subtype of the return type of the overridden member
    'fun asyncLoad(key: K, executor: Executor): CompletableFuture<out V>' defined in 'CoroutineAsyncCacheLoader'.
CoroutineAsyncCacheLoaders.kt:32:8 
    Return type of 'asyncReload' is not a subtype of the return type of the overridden member 
    'fun asyncReload(key: K, oldValue: @NonNull() V & Any, executor: Executor): CompletableFuture<out V>' defined in 'CoroutineAsyncCacheLoader'.
CoroutineCacheImpl.kt:18:43 
    Argument type mismatch: actual type is 'V?', but 'V' was expected.
> Task :caffeine-coroutines:compileKotlin FAILED

Is it expected that when Java libraries adopt nullability annotations, downstream Kotlin users should expect these types of compilation failures? Is this strictly a source incompatible change or are there binary compatibility aspects that Kotlin imposes on their call sites to be aware of?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked caffeine-coroutines pull request and the referenced CoroutineAsyncCacheLoaders.kt and CoroutineCacheImpl.kt files, then compare the Kotlin compiler errors with the Java API's nullability annotations. Determine whether adopting annotations creates source or binary compatibility changes for Kotlin callers, and record the compatibility guidance or required follow-up.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
developer-experience, devtools
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.