Small question regarding how to fix a 'UR'-anomaly please.
On this very simple piece of code:
private final Environment environment;
private final Map<String, Foo> partnerConfiguration;
@Value("something")
private List<String> goodCities;
@PostConstruct
public void setup() {
for (final String city : goodCities) {
final String nameAndCountry = environment.getProperty(PROPERTY_PREFIX + city);
final String[] nameAndCountrySplit = Objects.requireNonNullElse(nameAndCountry, "").split(";");
final String name = nameAndCountrySplit[0];
final String country = nameAndCountrySplit[1];
partnerConfiguration.put(city, new Foo(name, country));
}
}
I got flagged with 'UR'-anomaly on those lines:
public void setup() {
for (final String city : goodCities) {
final String nameAndCountry = environment.getProperty(PROPERTY_PREFIX + city);
I tried using a functional version of it, refactoring by creating a sub method, changing variable names, no luck.
I know static analysis tools are just tools, but I am quite interested what would be the code level answer on how to fix this "anomaly" please.
Thank you
question from:
https://stackoverflow.com/questions/65829316/found-ur-anomaly-for-variable-city-lines-xx-yy 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…