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

后端 未结 8 1626
遇见更好的自我
遇见更好的自我 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 05:59

    Date is mutable

    and you are not creating a copy of Date that came in to you are parameter. So if the client code will change the value of the Date object, it will affect your class too.

    Solution is to create a copy of Date

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

提交回复
热议问题