简体   繁体   English

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

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

I have a field name which is similar to static constant我有一个类似于静态常量的字段名称

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

I'm getting sonar warning:我收到声纳警告:

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

Although field is instance and constant isn't a method and also static虽然字段是实例,常量不是方法,也是静态的

Is it false positive sonar warning, a corner case I should suppress or is there a real issue in my code and I need to move constant outside class (or inner class)?是误报声纳警告,我应该抑制的极端情况还是我的代码中存在真正的问题并且我需要将常量移到类(或内部类)之外?

I found other false positive for this warning, but it was fixed, Builder pattern :我发现此警告的其他误报,但已修复, Builder 模式

S1845 should not raise issue on builders and methods returning the field with same name S1845 不应引发返回同名字段的构建器和方法的问题

It wouldn't cause an issue when building your source code, so from that perspective you could suppress it, but it might generate confusion to the developer/reviewer, so it would be best to fix it (especially when working with autocomplete, although the field is private in this case...) .在构建源代码时它不会导致问题,因此从这个角度来看,您可以抑制它,但它可能会给开发人员/审查者带来混乱,因此最好修复它(尤其是在使用自动完成功能时,尽管在这种情况下,字段是私有的...)。 Maybe use a different naming pattern for local variables.也许对局部变量使用不同的命名模式。 Different scope would also fix this.不同的范围也可以解决这个问题。

I found also this link where they try to describe this, although they focus mostly on methods, and the 'Compliant Solution' is in tune with the links you've shared regarding the BuilderPattern: https://rules.sonarsource.com/java/tag/confusing/RSPEC-1845我还发现了他们试图描述这一点的链接,尽管他们主要关注方法,并且“合规解决方案”与您分享的关于 BuilderPattern 的链接一致: https ://rules.sonarsource.com/java /标签/混淆/ RSPEC-1845

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

相关问题 SonarQube 鱿鱼中的假阳性:S2583 - False positive in SonarQube squid:S2583 Sonarqube鱿鱼:S2095假阳性 - Sonarqube squid:S2095 false positive 使用Spring autowire时,Servlet不应该有可变实例字段误报(squid:S2226) - Servlets should not have mutable instance fields false positive with Spring autowire (squid:S2226) 应使用 lambda 删除未使用的方法参数 (squid:S1172) 误报 - Unused method parameters should be removed (squid:S1172) false positive using lambda 鱿鱼:S2583 –使用开关时,Sonarqube误报 - squid:S2583 – Sonarqube false positive when using switch SonarQube假阳性鱿鱼:S1450用于@Getter(lombok)注释字段 - SonarQube false positive squid:S1450 for @Getter (lombok) annotated fields 包名称应符合命名约定(squid:S00120)和下划线 - Package names should comply with a naming convention (squid:S00120) and underscore SonarQube静态方法中的假阳性“应删除未使用的私有方法” - SonarQube false-positive “unused private methods should be removed” in static method Eclipse SonarLint 误报“应删除未使用的分配 (java:S1854)” - Eclipse SonarLint false positive “Unused assignments should be removed (java:S1854)” JUnit断言方法应该用正面还是负面的措辞? - JUnit assertion methods should be phrased in the positive or the negative?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM