Oversized Type
ID |
java.max_class_lines |
Severity |
high |
Remediation Complexity |
medium |
Remediation Risk |
low |
Remediation Effort |
medium |
Resource |
Complexity |
Language |
Java |
Tags |
complexity |
Description
Reports top-level types — classes, interfaces, enums and records — that hold more lines of code than the configured limit.
The measure counts only the lines that carry code. Blank lines, comment-only lines and Javadoc are ignored, so a well documented type is never penalised for its documentation.
Rationale
A type that keeps growing ends up owning several unrelated responsibilities at once. The symptoms are familiar: nobody can hold the whole thing in their head, every change carries a risk of breaking something unrelated, merge conflicts become routine because several people always have a reason to touch the file, and the test suite for it either does not exist or takes an afternoon to understand.
public class OrderProcessor {
// parsing the incoming payload
// validating business rules
// computing taxes and discounts
// persisting to the database
// rendering the confirmation e-mail
// ... 900 lines later
}
Only top-level types are measured. A nested type is part of its enclosing type’s body, so measuring both would report the same code twice; the enclosing type is the unit that has to be split.
Remediation
List the responsibilities the type currently covers and give each one its own type. Common cuts: separate parsing from validation, move persistence behind a dedicated repository, extract rendering or formatting, and push cross-cutting concerns such as logging or metrics into decorators.
public class OrderProcessor {
private final OrderValidator validator;
private final PriceCalculator prices;
private final OrderRepository repository;
private final ConfirmationMailer mailer;
public void process(OrderPayload payload) {
Order order = validator.validate(payload);
prices.apply(order);
repository.save(order);
mailer.confirm(order);
}
}
If the type is a genuine aggregate of small, cohesive members — a constant holder or a generated data model — raise maxLines for the project rather than forcing an artificial split.