Query module WhitespaceContradictsPrecedence

name
Whitespace contradicts operator precedence
description
Nested expressions where the formatting contradicts the grouping enforced by operator precedence are difficult to read and may even indicate a bug.
kind
problem
problem.severity
warning
precision
very-high
id
java/whitespace-contradicts-precedence
tags
maintainability readability external/cwe/cwe-783

Imports

java

Provides all default Java QL imports.

Predicates

endOfBinaryLhs
interestingNesting

Find nested binary expressions where the programmer may have made a precedence mistake.

operatorWS

Compute whitespace around the operator.

startOfBinaryRhs

Classes

ArithmeticExpr

A binary expression using the operator +, -, *, /, or %.

AssocNestedExpr

A binary expression of the form x op y, which is itself an operand (say, the left) of another binary expression (x op y) op' y such that (x op y) op' y' = x op (y op' y), disregarding overflow.

HarmlessNestedExpr

A binary expression nested inside another binary expression where the inner operator “obviously” binds tighter than the outer one. This is obviously subjective.

LogicalExpr

A binary expression using the operator && or ||.

RelationExpr

A binary expression using the operator ==, !=, <, >, <=, or >=.

ShiftExpr

A binary expression using the operator <<, >>, or >>>.