Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringValue.of compiles when passed a null value #18672

Open
rooday-doordash opened this issue Oct 8, 2024 · 0 comments
Open

StringValue.of compiles when passed a null value #18672

rooday-doordash opened this issue Oct 8, 2024 · 0 comments
Assignees
Labels

Comments

@rooday-doordash
Copy link

Related to detekt/detekt#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:

  1. Write code that uses StringValue.of(null)
  2. Compile (this will be successful)
  3. Run and get an NPE

More specifically, I wrote Kotlin code like this:

SomeProtobufBuilder.apply {
    nullableString.let {
        this.stringProperty = StringValue.of(it)
    }
}

This code is buggy, as it allows StringValue.of(nullableString) even when it is null. It should've been:

SomeProtobufBuilder.apply {
    nullableString?.let {
        this.stringProperty = StringValue.of(it)
    }
}

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?

@rooday-doordash rooday-doordash added the untriaged auto added to all issues by default when created. label Oct 8, 2024
@JasonLunn JasonLunn removed the untriaged auto added to all issues by default when created. label Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants