obabichevjb opened a new issue, #16487: URL: https://github.com/apache/dubbo/issues/16487
### Pre-check - [x] I am sure that all the content I provide is in English. ### Search before asking - [x] I had searched in the [issues](https://github.com/apache/dubbo/issues?q=is%3Aissue) 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? - [x] Yes I am willing to submit a pull request on my own! ### Code of Conduct - [x] I agree to follow this project's [Code of Conduct](https://www.apache.org/foundation/policies/conduct) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
