Malicious code vulnerability - May expose internal representation by incorporating reference to mutable object

后端 未结 8 1589
遇见更好的自我
遇见更好的自我 2020-11-27 05:00

I have the following code in my dto class.

public void setBillDate(Date billDate) {
    this.billDate = billDate;
}

And I get an error in s

8条回答
  •  北海茫月
    2020-11-27 06:02

    I wonder why none of the solutions takes null into consideration. A general, null-safe solution should look like this:

    public void setBillDate(Date billDate) {
        this.billDate = billDate != null ? new Date(billDate.getTime()) : null;
    }
    

提交回复
热议问题