方法和字段名称不应仅因大小写不同 (squid:S1845) 误报

Methods and field names should not differ only by capitalization (squid:S1845) false positive

我有一个类似于静态常量的字段名

public static final String MAIL = "mail";
private String mail;

我收到声纳警告:

`Methods and field names should not be the same or differ only by capitalization (squid:S1845)`

尽管字段是实例并且常量不是方法而且也是静态的

它是误报声纳警告,我应该抑制的极端情况,还是我的代码中存在真正的问题,我需要将常量移到 class 之外(或内部 class)?

我发现了此警告的其他误报,但已修复,Builder pattern:

S1845 should not raise issue on builders and methods returning the field with same name

它不会在构建您的源代码时造成问题,因此从这个角度来看您可以抑制它,但它可能会给 developer/reviewer 带来混乱,因此最好修复它(尤其是使用自动完成时,尽管在这种情况下该字段是私有的...)。也许对局部变量使用不同的命名模式。 不同的范围也可以解决这个问题。

我也发现了这个 link 他们试图描述这一点,尽管他们主要关注方法,并且 'Compliant Solution' 与您分享的 link 一致关于 BuilderPattern: https://rules.sonarsource.com/java/tag/confusing/RSPEC-1845