Commented-Out Code

ID

java.commented_out_code

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Code Smell

Language

Java

Tags

code-style

Description

Reports blocks of commented-out code. Detects multi-line block comments (/* …​ */) and consecutive single-line comments (//) that contain Java-like syntax such as keywords, semicolons, or braces.

Rationale

Commented-out code is dead weight. It clutters the source, confuses readers about what is active, makes diffs noisier, and inevitably drifts out of sync with the live code. Version control already preserves history; there is no need to keep old code in comments.

// Bad — commented-out code block
// if (value > 0) {
//   return value;
//   doWork();

// Good — use version control to preserve old code
public void doWork() {
    // descriptive comment about behavior
    value = 42;
}

Remediation

Delete the commented-out code. If the code may be needed later, rely on version control history to retrieve it.