【发布时间】:2021-12-20 21:38:58
【问题描述】:
在 SonarQube 扫描中,它在下面提到的行中显示了一个主要错误。问题是,单例类以非同步方式写入字段。我无法弄清楚,为什么这是一个问题?
@Configuration
@ConfigurationProperties(prefix = "app")
public class UrlConfigs() {
@Autowired
private List<UrlItems> item;
//Getter & Setter
}
@Component
public class UrlItems {
private String url;
private String location;
// Getter
public void setUrl(String url){
this.url = url; // ISSUE: Singleton class writes to a field in an unsynchronized manner
}
public void setLocation(String location) {
this.location = location; // ISSUE: Singleton class writes to a field in an unsynchronized manner
}
}
【问题讨论】:
标签: java spring spring-boot sonarqube