Projects using the Lombok @ Data annotations, reduce a lot of template code, make the code more concise, but due to special project, you need to use FindBug scanning loopholes, the result is to scan a lot of "May expose internal representation by returning reference to mutable object" error, (returns a mutable object reference and keep it in object fields will expose objects within the field description)
By this time have a more stupid way, manually write the get and set methods, avoid this problem, but always felt a bit silly ~
Public Date getXxxTime () {
If (XxxTime!=null) {
Return (Date) xxxTime. Clone ();
}
return null;
}
Public void setXxxTime (Date xxxTime) {
If (xxxTime!=null) {
This. XxxTime=(Date) xxxTime. Clone ();
}
}
Lombok whether there are better get unified custom part attribute types, set method?
CodePudding user response:
Ask bosses how to solve