However, neither IntelliJ nor Detekt flagged this during static analysis. Detekt says this isn't an issue on their end if the code compiles properly, so I'm guess there's an issue with how StringValue.of (and potentially all wrapper classes .of) type check their passed arguments.
When I hover over .of in IntelliJ, I see
@NotNull
@Contract("_->new")
public static StringValue of(
@NotNull String value
)
It says it takes a @NotNull String, yet it didn't throw a compiler error when a nullable string was passed.
What did you expect to see
I expected to get a compiler error.
What did you see instead?
The error was hidden until runtime.
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Anything else we should know about your project / environment
Potentially this is an issue of Kotlin <-> Java interop?
Related to https://github.com/detekt/detekt/issues/7707
What version of protobuf and what language are you using? Version: protobuf-java:3.25.3 Language: Kotlin
What operating system (Linux, Windows, ...) and version? Mac OS X 14.7 aarch64
What runtime / compiler are you using (e.g., python version or gcc version) Gradle 8.8, Kotlin 1.6.10
What did you do? Steps to reproduce the behavior:
More specifically, I wrote Kotlin code like this:
This code is buggy, as it allows StringValue.of(nullableString) even when it is null. It should've been:
However, neither IntelliJ nor Detekt flagged this during static analysis. Detekt says this isn't an issue on their end if the code compiles properly, so I'm guess there's an issue with how
StringValue.of
(and potentially all wrapper classes.of
) type check their passed arguments.When I hover over
.of
in IntelliJ, I seeIt says it takes a
@NotNull String
, yet it didn't throw a compiler error when a nullable string was passed.What did you expect to see I expected to get a compiler error.
What did you see instead? The error was hidden until runtime.
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
Anything else we should know about your project / environment Potentially this is an issue of Kotlin <-> Java interop?