liveBook · Manning

Condition dominance

As explained in 100 Java Mistakes and How to Avoid Them

Condition dominance is a control-flow relationship in which one condition can be true only when another condition is also true, making the dominated branch unreachable when tested afterward.

Condition dominance occurs when condition Y can be true only if condition X is also true. In an if–else chain, testing X first makes Y unreachable, so branch order changes the result. section 3.2

Age-range mistake

Testing age >= 6 before age >= 18 classifies every adult as CHILD; the FULL branch is never reached. Use mutually exclusive ranges or test the narrower condition first. section 3.2

Check for dominance when:

  • Ordering numeric ranges, test specific or bounded ranges before broader ones. section 3.2
  • Ordering instanceof checks, test subclasses such as BigInteger and BigDecimal before Number. section 3.2
  • Reviewing chains, use static analysis to find conditions reported as always false, then verify whether the warning reflects intended logic. section 3.2

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Explains dominance through numeric ranges and type hierarchies, then applies static-analysis checks without developing formal control-flow theory.
Examples
Uses age tariffs, BigInteger conversion, FizzBuzz ordering, and corrected Java type-pattern switches.
What you can do after
Diagnose unreachable branches, reorder overlapping tests, and validate suspected dominance with static analysis.
How it connects
Connects ordered conditions with if–else chains, numeric ranges, instanceof checks, type hierarchies, and static analysis.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.