Findbugs reports many EI_EXPOSE_REP and EI_EXPOSE_REP2 errors in my code, every time I write getters and setters as follows:
public Date getDate() { return date; } public void setDate(final Date date) { this.date = date; }
I understand the meaning of the report, I should not disclose the internal links of my object to the outside world, so that they can not be changed by malicious / offensive code. Correction:
public Date getDate() { return date == null ? null : date.clone(); } public void setDate(Date date) { this.date = date == null ? null : date.clone(); }
My question is not here. I am surprised that this report ALWAYS concerns date. Why not all other mutable objects? I think this report also applies to all mutable objects, right?
Should I extend this โgood practiceโ to all my accessors associated with mutable objects?
Give me your advice, thanks
source share