Excessive Fan-Out

ID

java.excessive_fan_out

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Complexity

Language

Java

Tags

complexity, design

Description

Reports compilation units whose non-JDK fan-out exceeds a configurable threshold. Fan-out is the number of distinct external types a file depends on; a very high fan-out is a strong indicator of a god-class or monolithic component that should be decomposed.

Rationale

High fan-out means the class needs to know about many collaborators, which makes it fragile (any of them changing can break it), hard to test (each collaborator is another thing to stub), and hard to reason about (no single responsibility). Splitting the class by responsibility usually drops fan-out significantly on each piece.

Fan-out is counted from the import statements in the compilation unit, excluding JDK / Jakarta packages (java., javax., jakarta.*) which every class uses and would drown the signal. Static imports of members of the same type collapse to a single contribution. Test classes are skipped because tests legitimately pull in mocks, fixtures and many production types.

Remediation

Identify the distinct responsibilities the class is trying to cover and extract each one into its own class. Typical splits: extract persistence from business logic, separate event handling from state management, or push cross-cutting concerns (logging, metrics) into aspects or decorators.

Configuration

Property Default Description

maxFanOut

20

Number of distinct non-JDK imports strictly greater than this value is flagged.