I am in my early days as a developer and need help to resolve the Sonar error which says double assignment of field for the below code.
//Inside constructor
list1 = new ArrayList();
....
...
// in some method
if(description.equalsIgnoreCase(MAPPED_CATIA_MODELS)) {
tempList = new ArrayList();
tempList = list1 ; // gives error here as "Correctness - Double assignment of field."
addKey = true;
}
Please suggest what needs to be changed.
Thanks.
Sonar is suggesting you remove one of either
tempList = new ArrayList();or
tempList = list1;The point is right after you created an ArrayList, you overwrote the reference to it with a reference to list1. The result of
new ArrayList()is immediately thrown away and gone forever.