The following piece of code is being flagged by SonarQube as having a UR anomaly when running PMD rules, which is baffling to me:
public void doSomething(String filename) {
final Resource resource = new ClassPathResource(filename);
//do something with the resource ...
}
I can understand a DU (because the variable is short lived) but why a UR?
According to data flow analysis papers UR stands for "Undefined-Referenced" and DU stands for "Defined-Undefined".
The first one refers to when you are referencing an undefined variable (a possible bug) and he second one refers to when a recently defined variable is undefined (such as when you go out of scope and that variable is de-referenced).