How to solve EI_EXPOSE_REP2 and why exactly it is wrong

I ran FindBugs on my project and I received the following warning:

new foo.pkg.Key(Client, Product, Date, String) may expose internal representation by storing an externally mutable object into Key.expireDate   MALICIOUS_CODE  EI_EXPOSE_REP2  60  Medium

Keyis an Entity that has Date expireDate, with its corresponding getter and setter, and it uses them in the constructor.

So what happened? Why is this wrong? Is it because Date is a mutable type?

In fact, I just return (Date) dataNascimento.clone()and use the same strategy in the installer. Is this the best way to do this?

+3
source share
1 answer

I would recommend making a call (Date) dataNascimento.clone()in the constructor (directly or through your setter).

, FindBugs - , . , , .

+6

All Articles