[Java] False Positive for S1845 (Methods and field names should not be the same...)

144 views
Skip to first unread message

vlot...@evelopers.com

unread,
Sep 12, 2017, 5:02:47 AM9/12/17
to SonarQube
Dear team,

I think that constants should be excluded from the logic in S1845. To me there is nothing wrong in the code like:

public class A {
    private static final String URL = "some url";
    public URI[] url;
}


Regards,
Vadim

simon schrottner

unread,
Sep 12, 2017, 5:31:50 AM9/12/17
to SonarQube
well it is correct code... but hard du know as a dev, and easy to mix up, clean code is not always about if the code is correct -> it also about understandibility

vlot...@evelopers.com

unread,
Sep 12, 2017, 6:38:03 AM9/12/17
to SonarQube
Simon,

       As a developer, agree that it is rather hard to mix up constant and field. I agree that it is rather easy to mix up "url" and "url()". To me it is impossible to mix up "URL" and "url". We have already convention for the constants - their names should be capitalized - exactly for the purpose of understandability.
      
Regards,
Vadim

Nicolas Peru

unread,
Sep 26, 2017, 9:35:53 AM9/26/17
to vlot...@evelopers.com, SonarQube
Hi, 

Even though I understand your line of thought I think it is not really nice for user of your class to have this mixing of two different things only differing by capitalization (which is precisely the point of the rule). I think that excluding this case would actually make the rule a bit useless, so if you disagree with this rule I would rather recommend you to deactivate it and/or mark this case as won't fix (as I tend to think that this is not (and should probably not be) a generalized practice). 

Cheers, 

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/b4499a54-7a2b-4e06-965b-0258cbcd010b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Nicolas Peru | SonarSource
Reply all
Reply to author
Forward
0 new messages