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

@Nullable annotation is missing from methods that may return null #732

Closed
m15o opened this issue Jun 7, 2024 · 4 comments · Fixed by #744
Closed

@Nullable annotation is missing from methods that may return null #732

m15o opened this issue Jun 7, 2024 · 4 comments · Fixed by #744

Comments

@m15o
Copy link
Contributor

m15o commented Jun 7, 2024

We have kotlin test codes using BraveTracer, but we get inaccurate warnings from the kotlin compiler.

For example, following code is warnde by the compiler with Unnecessary safe call on a non-null receiver of type Span message:

internal class TracerTest {
    @Test
    fun test() {
        val tracing = brave.Tracing.newBuilder().build()
        val tracer = BraveTracer(tracing.tracer(), BraveCurrentTraceContext(tracing.currentTraceContext()))
        assertThat(tracer.currentSpan()?.context()?.traceId()).isNull()
    }
}

This is because io.micrometer.tracing.brave.bridge package have @NonNullApi, but BraveTracer.currentSpan() do not have @Nullable annotation.
We are not sure, but other methods might also missing @Nullable annotation.

@marcingrzejszczak
Copy link
Contributor

Yikes! Are you willing to file a PR to help us out?

@ttddyy
Copy link
Contributor

ttddyy commented Jun 7, 2024

But shouldn't it inherit @Nullable from the interface even though they are in different packages?
I see Tracer.currentSpan() interface is annotated with @Nullable.

@m15o
Copy link
Contributor Author

m15o commented Jun 7, 2024

By type castting BraveTracer to Tracer, the warning goes away.
I think BraveTracer has narrower type, so if you use BarveTracer itself, the BraveTracer.currnet() is treated as not-null.

@ttddyy
Copy link
Contributor

ttddyy commented Jun 8, 2024

Looking at Spring Framework, the implementation class also declares @Nullable if the method could return null.
For example, RestOperation interface against RestTemplate implementation class.

So, I think it would be a good PR for @m15o to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants