Skip to content

MissingJavadocType: with scope as 'package' demands javadoc on inner class in method #13749

@chris21k

Description

@chris21k

https://checkstyle.org/checks/javadoc/missingjavadoctype.html#MissingJavadocType
https://checkstyle.org/property_types.html#Scope

Checkstyle (currently using 10.12.3) claims missing javadoc at line 12 (that is line 11 in the file Test.java) for named local class A although javadoc comments are never located in method blocks:

/var/tmp$ java --version
openjdk 21 2023-09-19
OpenJDK Runtime Environment (build 21+35-2513)
OpenJDK 64-Bit Server VM (build 21+35-2513, mixed mode, sharing)
/var/tmp$ javac Test.java

/var/tmp$ cat checks.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocType">
        <property name="scope" value="package"/>
        <!--property name="excludeScope" value="anoninner"/-->
    </module>
  </module>
</module>

/var/tmp$ cat Test.java
/**
 * Example program using a named lokal class.
 */
public class Test {
  /**
   * Start the program execution.
   *
   * @param args Command line arguments, currently ununsed.
   */
  public void main(final String[] args) {
    class A {            // violation, 'Missing a Javadoc comment'
      private String msg = "Hello, World!";

      private String getMsg() {
        return msg;
      }
    }
    A a = new A();
    System.out.println(a.getMsg());
  }
}

/var/tmp$ java -Duser.language=en -Duser.country=US -jar checkstyle-10.12.3-all.jar -c checks.xml Test.java
Starting audit...
[ERROR] /var/tmp/Test.java:11:5: Missing a Javadoc comment. [MissingJavadocType]
Audit done.
Checkstyle ends with 1 errors.

The scope package property of the module MissingJavadocType should indicate to test types/classes in scope package or more liberal. However, it triggers also named local types, whose scope is local.
Activating property excludeScope anoninner prevents the error message, however, inner class A is non anonymous, i.e., it is named.

$ cat config.xml 
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
          "-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
          "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
  <module name="TreeWalker">
    <module name="MissingJavadocType">
        <property name="scope" value="package"/>
        <property name="excludeScope" value="anoninner"/>
    </module>
  </module>
</module>
$ java -jar checkstyle-10.20.0-all.jar -c config.xml Test.java 
Starting audit...
Audit done.

The dcoumentation of Module MissingJavadocType can be found at https://checkstyle.sourceforge.io/checks/javadoc/missingjavadoctype.html .

Thanks for looking into it,
Chris

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions