#16487·dubbo

[Bug] Consumer-facing API lacks nullability annotations, defeating Kotlin null-safety

Author: obabichevjbCreated Sep 28, 2026Updated Sep 28, 2026
Labelstype/need-triagecomponent/need-triage

Pre-check

  • I am sure that all the content I provide is in English.

Search before asking

  • I had searched in the issues and found no similar issues.

Apache Dubbo Component

Java SDK (apache/dubbo)

Dubbo Version

Dubbo Java 3.3.6, OpenJDK 21 (Amazon Corretto 21.0.5), macOS 15.6 Kotlin 2.4.20, Gradle 9.5 (the issue is OS-independent)

Steps to reproduce this issue

A Kotlin project with a single dependency on org.apache.dubbo:dubbo:3.3.6. No provider, consumer, registry or network is needed — RpcContext alone is enough.

build.gradle.kts:

kotlin
plugins {
    kotlin("jvm") version "2.4.20"
    application
}
repositories { mavenCentral() }
dependencies { implementation("org.apache.dubbo:dubbo:3.3.6") }
kotlin { jvmToolchain(21) }
application { mainClass = "MainKt" }

src/main/kotlin/Main.kt:

kotlin
import org.apache.dubbo.rpc.RpcContext

fun main() {
    val ctx = RpcContext.getClientAttachment()

    // getAttachment() returns null for an absent key...
    println("raw value: " + ctx.getAttachment("no-such-key"))

    // ...but it carries no @Nullable, so Kotlin lets it into a non-null String
    // with no warning and no error. This line should not compile.
    val value: String = ctx.getAttachment("no-such-key")

    println("never reached: ${value.length}")
}

Then:

$ ./gradlew compileKotlin --rerun-tasks
BUILD SUCCESSFUL

Compiles cleanly. --warning-mode all and a forced full recompile also produce zero warnings. At runtime:

$ ./gradlew run
raw value: null
Exception in thread "main" java.lang.NullPointerException: getAttachment(...) must not be null
	at MainKt.main(Main.kt:11)

What you expected to happen

Expected: the assignment should be a compile error. getAttachment(String) returns null for an absent key, so assigning its result to a non-null String is provably wrong and a compiler can say so.

Actual: it compiles with no diagnostic, and fails at runtime instead.

Anything else

No response

Do you have a (mini) reproduction demo?

  • Yes, I have a minimal reproduction demo to help resolve this issue more effectively!

Are you willing to submit a pull request to fix on your own?

  • Yes I am willing to submit a pull request on my own!

Code of Conduct