Rule Set: basic.html#SimplifiedTernary
Description: I have a special case where to save money in my database, I return null if a boolean value is false in a method of return type Boolean.
Code Sample demonstrating the issue:
@Nullable
public Boolean getHasCustomName() {
return mHasCustomName ? true : null; // From my understanding of Java, this cannot be simplified.
}
Running PMD through: Gradle
Thanks for reporting. This bug will be fixed with PMD 5.4.5, 5.5.4, and later.
@adangel Has this really been fixed for 5.5.4? Because for me 5.5.4 still has this issue, although with a slightly different piece of code:
setToogle(varOfBooleanClass != null ? varOfBooleanClass : false);
@sschuberth actually that is not a false positive. The rule is right, you could rewrite that without the conditional as:
setToogle(varOfBooleanClass != null && varOfBooleanClass);
@jsotuyod Doh, you're right, thanks for opening my eyes!
Most helpful comment
@sschuberth actually that is not a false positive. The rule is right, you could rewrite that without the conditional as: