Vamsidhar :
Sonar rule squid:S2384 raises an issue on this code:
public Date getCreatedOn() {
return createdOn;
}
following the rule Mutable members should not be stored or returned directly
I understand that we should not return the original, instead we should return a copy of the object.
On the other hand, Sonar does not raise an issue on this code:
public Date getCreatedOn() {
return this.createdOn;
}
What makes this code different?
Are we not returning the original copy in the 2nd case?
Tibor Blenessy :
This is a deficiency in a way how SonarJava (Java static code analyzer used in SonarQube platform) detects this issue. I created following ticket to improve the implementation to cover cases when field is returned using this
.
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=444304&siteId=1