Menu

#358 new rule: date getter without clone

open
nobody
None
5
2013-02-16
2011-09-25
No

If you return a java.util.Date field from a getter then it *needs* to be cloned or some other thread/consumer could easily modify it.

Example:
class Foo {
Date x
Date getX() {
return x // violation
}
Date getX_2() {
return x.clone() // OK
}
}

Discussion


Log in to post a comment.