Search code examples
javamavencheckstylemaven-checkstyle-plugin

How to enable checkstyle's MissingOverride check?


I have a

public interface Interface0 {

    void method0();
}

and a

public class Implementation0 implements Interface0 {

    public void method0() {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}

and I'm using the maven-checkstyle-plugin by declaring

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-checkstyle-plugin</artifactId>
    <version>3.0.0</version>
    <executions>
        <execution>
            <id>checkstyle</id>
            <phase>validate</phase>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <configLocation>${basedir}/check_style.xml</configLocation>
    </configuration>
</plugin>

and finally I'm activating MissingOverride in check_style.xml:

<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
   "-//Puppy Crawl//DTD Check Configuration 1.2//EN"
   "http://www.puppycrawl.com/dtds/configuration_1_2.dtd">
<module name="Checker">
    <module name="TreeWalker">
        <module name="MissingOverride"/>
    </module>
</module>

This is the extract of my experience in many projects that all checks work fine, except for MissingOverride which has no effect, i.e. doesn't detect a single missing @Override annotation.


Solution

  • The documentation of the MissingOverride module states:

    Verifies that the java.lang.Override annotation is present when the {@inheritDoc} javadoc tag is present.

    Documentation link

    In other words, its not intended to check what you want it to check - it only checks if the use of the {@inheritDoc} tag in the Javadoc comment is paired with an @Override annotation.