You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[java] UnconditionalIfStatement: False negative for negated boolean constant #6435
Description:
UnconditionalIfStatement fails to detect cases where the condition is an effectively constant boolean expression, such as a UnaryExpression involving a boolean literal (e.g., if (!false)).
In the AST, !false is parsed as a UnaryExpression containing a BooleanLiteral, which does not satisfy the current [BooleanLiteral[1]] predicate. This allows unconditional code blocks to bypass static analysis simply by adding a logical NOT operator.
PMD should report a violation at line 4, but doesn't. This is a false-negative. The rule should be updated to account for simple constant expressions or at least unary-negated literals.
changed the title [-]UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/-][+][java] UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/+]on Feb 16, 2026
changed the title [-][java] UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/-][+][java] UnconditionalIfStatement: False negative for negated boolean expression[/+]on Feb 16, 2026
changed the title [-][java] UnconditionalIfStatement: False negative for negated boolean expression[/-][+][java] UnconditionalIfStatement: False negative for negated boolean constant[/+]on Feb 16, 2026
Activity
[-]UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/-][+][java] UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/+][-][java] UnconditionalIfStatement: False negative when boolean literal is wrapped in UnaryExpression[/-][+][java] UnconditionalIfStatement: False negative for negated boolean expression[/+][-][java] UnconditionalIfStatement: False negative for negated boolean expression[/-][+][java] UnconditionalIfStatement: False negative for negated boolean constant[/+]adangel commentedon Feb 16, 2026
Thanks for reporting.
By adding single not, you would change the semantic. But the easier way to bypass this rule is
!!true...[java] Fix pmd#6435: UnconditionalIfStatement flags arbitrarily negat…
[java] Fix #6435: UnconditionalIfStatement flags arbitrarily negated …