Why is returning this.variable not a vulnerability?

The squid: S2384 sonar rule causes a problem with this code:

public Date getCreatedOn() {
    return createdOn;
}

following the Mutable rule, 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.

Sonar, on the other hand, does not cause a problem with this code:

public Date getCreatedOn() {
    return this.createdOn;
}

What is the difference between this code?

Will we not return the original copy in the second case?

+6
source share
2 answers

, SonarJava (Java- , SonarQube) . , , , this.

https://jira.sonarsource.com/browse/SONARJAVA-2424

+10

. , , .

, , , . .

-2

All Articles