Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering
SA: Self comparison
SA_LOCAL_SELF_COMPARISON:“This method compares a local variable with itself, and may indicate a typo or a logic error. Make sure that you are comparing the right things.” – 2013-12-09
SA_FIELD_SELF_COMPARISON: “This method compares a field with itself, and may indicate a typo or a logic error. Make sure that you are comparing the right things.” – 2013-12-09
It will happen when we have a condition which compares a
with itself. This will always be true or false. So most likely the programmer will have intended to compare with the another element.
Here we have one example for this problem (it can occur in while or for condition as well):
<code Java> public class test {
static int y=0; public void selfCompareOfField(Integer x) { if (y>=y){ x=0; } } public void selfCompareOfParameter(int x) { if (x>=x){ x=0; } } public void selfCompareOfLocalVar() { int x = 0; if (x>=x){ x=0; } }
}
</Code>
Benchmark project | Precision | Recall | ||||
---|---|---|---|---|---|---|
FB | JT | Delta | FB | JT | Delta | |
Project … | …% | …% | …% | …% | …% | …% |
Project … | …% | …% | …% | …% | …% | …% |
FB = FindBugs, JT = JTransformer, Delta = JTransformer - FindBugs