简体   繁体   English

如果使用@Nonnull 进行注释,则没有针对 null 返回值的 FindBugs 警告

[英]No FindBugs warning for null return value if annotated with @Nonnull

I have annotated a method returning null with the @javax.annotations.Nonnull annotation but FindBugs does not generate any warnings on this.我已经用@javax.annotations.Nonnull注释注释了一个返回null的方法,但 FindBugs 没有对此产生任何警告。

@Nonnull
public EventBuilder forCreateEvent() {
    return null;
}

Maybe I misunderstood the meaning of @Nonnull but I thought it means Method will not return null .也许我误解了@Nonnull的含义,但我认为这意味着Method 不会返回 null

Additional comment: Please see my comment below for the cause of the problem.附加评论:请参阅下面我的评论以了解问题的原因。

The annotations that Findbugs understands are documented here . Findbugs 理解的注释记录在此处

At the time I originally answered this question, the javax.annotations.* annotations are not listed.在我最初回答这个问题的时候, javax.annotations.*注释没有列出。 They are listed now.他们现在列出。

As assylias said, May be its conflicting.正如 assylias 所说,可能是自相矛盾的。 Try changing it to尝试将其更改为

@edu.umd.cs.findbugs.annotations.NonNull
public EventBuilder forCreateEvent() {
    return null;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM