Javadoc Content
ID |
java.javadoc_content |
Severity |
low |
Remediation Complexity |
auto_fix |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Documentation |
Language |
Java |
Tags |
best-practice, documentation |
Description
Reports quality issues in existing Javadoc comments. Unlike java.missing_javadoc which checks whether Javadoc is present, this rule checks whether existing Javadoc is correct.
Rationale
Misleading Javadoc is worse than no Javadoc: callers read a wrong contract, generated reference pages carry stale statements, and outdated TODO markers leak into the public API surface. Keeping Javadoc internally consistent with the declaration it documents preserves the value of the doc for tooling and for API consumers.
Checks
-
@returnon void methods – A@returntag on a void method is misleading. -
@exceptioninstead of@throws– The@exceptiontag is a legacy synonym for@throws. Modern code should use@throwsconsistently. -
@paramtag order – When multiple@paramtags are present, they should appear in the same order as the method parameters for readability. -
TODO/FIXME in Javadoc – TODO and FIXME markers in Javadoc are visible to API consumers via generated documentation. They belong in implementation comments, not in the public API contract.
-
Misplaced comment – A non-Javadoc comment between a
/** */block and its declaration disconnects the Javadoc from the code it documents.
Configuration
| Property | Default | Description |
|---|---|---|
|
|
Flag |
|
|
Flag |
|
|
Flag |
|
|
Flag TODO/FIXME markers in Javadoc blocks |
|
|
Flag comments wedged between a Javadoc block and its declaration |
Remediation
Non-compliant code
/**
* Returns nothing.
* @return nothing at all
*/
public void doWork() { } // @return on void
/**
* Processes input.
* @exception IOException if I/O fails
*/
public void process() throws IOException { } // @exception instead of @throws
/**
* Adds numbers.
* @param b the second
* @param a the first
* @return the sum
*/
public int add(int a, int b) { return a + b; } // wrong @param order
/**
* TODO: finish this.
*/
public void incomplete() { } // TODO in Javadoc