This part of code is rejected by pmd in sonar:
public String getFoo() {
String foo = System.getProperty("foo");
if (foo == null) {
foo = System.getenv("foo");
} else if (foo == null) {
foo = "defaultFoo";
}
return foo;
}
It says "Avoid Literals In If Condition". Can someone tell me what's wrong with this or what this rule try to effect?
Why don't you use:
public String getFoo() {
String foo = System.getProperty("foo", "defaultFoo");
return foo;
}
It will return "defaultFoo"
if no property is found.