GeezerVison is showing github.com — [java] SimplifiedTernary: Incorrect ternary operation can be simplified. · Issue #232 · pmd/pmd
[java] SimplifiedTernary: Incorrect ternary operation can be simplified. #232Labels a:bugPMD crashes or fails to analyse a file. DescriptionRule 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 Activityadded a commit that references this issue on Feb 2, 2017This issue will close once commit fbd9d21 is merged into the 'main' branch.fbd9d21 changed the title [-][java] Incorrect ternary operation can be simplified.[/-] [+][java] SimplifiedTernary: Incorrect ternary operation can be simplified.[/+] on Feb 12, 2017adangel commented on Feb 12, 2017 Thanks for reporting. This bug will be fixed with PMD 5.4.5, 5.5.4, and later. added 2 commits that reference this issue on Feb 12, 2017This issue will close once commit ed77143 is merged into the 'main' branch.ed77143 This issue will close once commit fc1e90b is merged into the 'main' branch.fc1e90b sschuberth commented on Mar 21, 2017 @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);
jsotuyod commented on Mar 21, 2017 @sschuberth actually that is not a false positive. The rule is right, you could rewrite that without the conditional as:
setToogle(varOfBooleanClass != null && varOfBooleanClass); Reacted by Jon Bevan, Jessica Shin, Gaurav Ranade, Sören Henning and chiamyunqing sschuberth commented on Mar 21, 2017 @jsotuyod Doh, you're right, thanks for opening my eyes!
MetadataMetadataa:bugPMD crashes or fails to analyse a file. DevelopmentNo branches or pull requestsIssue actions
|