Hello,
I recently updated our quality profiles. In the process, S1192 was assigned severity Critical, which is the default from the Sonar Way. Since that moment, many projects have turned to be in a bad shape.
Now, of course duplicated literals are a possible source of bugs, but is this really critical? Looking at one project, I find:
- A class building some HTML. Naturally, there are some Strings like "</table>" in there. Will a constant like CLOSE_TABLE_TAG improve readability?
- Long SQL queries split across lines (because Java lacks multi-line Strings). Not surprisingly, some queries refer to the same columns, so they share fragments like ", a.partnerid as account_partnerid ". Defining a constant for that means that
- “Edit SQL fragment” in IntelliJ will not work anymore
- IntelliJ cannot detect that I refer to the wrong column
- I cannot immediately see what the column will be called to refer to in the following result set accesses
- Debug and warning messages. I may or may not change some of them to be more specific in the future. They may contain placeholders that I cannot immediately see if they are wrapped in a constant.
Since the code is actually quite clean and actually uses many String constants and enums, we have, all in all, about 95% of reported cases where changing would not improve anything, even do harm. It seems to be quite hard to filter out cases like the above automatically. I wonder whether a rule which so easily reports irrelevant places should really be enabled by default.
For the remaining cases, I wonder whether the default severity of Critical is justified. Nothing is really broken, after all. Is that more severe than possible null accesses?
What do you think?
Greetings,
Michael