I have sonar "Mutable members should not be stored or returned directly" issue in my java class. I have fixed it by below code but still sonar is giving me the same error
public class UserInfoImpl
{
List<UserInfo> userDetails = Collections.emptyList();
void perform()
{
List<UserInfo> userDetails = service.getUserDetails();
userDetails = new ArrayList<>(userDetails);
this.userDetails = Collections.unmodifiableList(userDetails);
}
public final List<UserInfo> getUserDetailList()
{
return userDetails; // sonar error happens at this line
}
}
does anyone have any idea?