openrewrite / rewrite-static-analysis

OpenRewrite recipes for identifying and fixing static analysis issues.
Apache License 2.0
31 stars 50 forks source link

org.openrewrite.staticanalysis.AvoidBoxedBooleanExpressions does not understand @NonNull annotations #349

Open blipper opened 2 weeks ago

blipper commented 2 weeks ago

What is the smallest, simplest way to reproduce the problem?

import lombok.@NonNull

class A {
    void foo(@NonNull Boolean b) {
        if(b) {
        }
}

What did you expect to see?

import lombok.@NonNull

class A {
    void foo(@NonNull Boolean b) {
        if(b) {
        }
}

What did you see instead?

import lombok.@NonNull

class A {
    void foo(@NonNull Boolean b) {
        if(Boolean.TRUE.equals(b)) {
        }
}

What is the full stack trace of any errors you encountered?

stacktrace output here

Are you interested in contributing a fix to OpenRewrite?

timtebeek commented 2 weeks ago

Thanks @blipper ; indeed seems reasonable not to make any changes to variables annotated as non-nullable. Another case where having nullability included in the type system would help: