You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug] Consumer-facing API lacks nullability annotations, defeating Kotlin null-safety #16487
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.
importorg.apache.dubbo.rpc.RpcContextfunmain() {
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}")
}
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!
Activity