Veit's Blog

Hej! đź‘‹ Welcome to my curated space of insights on software development and the tapestry of life.

Maven Plugin to check for Methods that are not implemented

2015-09-30

Recently my former colleague, IBM Champion and also highly regarded friend Oliver Busse wrote a blog post called “Quick-Tip: never forget empty methods anymore”. In summary, it can be stated that Oli throws an UnsupportedOperationException to signalize that a method is not implemented. I see this approach often and there is nothing wrong with that. But I think there are two disadvantages:

  1. In my humble opinion the usage of UnsupportedOperationExceptionto signalize that a method is not yet implemented is some kind of mistreatment. To raise UnsupportedOperationExceptiondoesn’t always means it’s not yet implemented.
  2. Another point is, that I don’t like that the developer doesn’t see any warnings before or while compiling. Imagine your are going to use a library. UnsupportedOperationExceptionis a runtime exception and not a checked exception so you never see your failure until the exception is raised (best in production mode ;)).

So I wrote a tiny maven plugin that introduces the @NotYetImplemented annotation. Methods with that annotation generate warnings while packaging the application.

Usage is some kind of very, very simple:

  • Install the plugin in your local maven repository (at this point it doesn’t make sense to commit it to Maven Central).
  • Add the dependecy to your pom.xml.
        <dependency>
            <groupId>com.pikodat</groupId>
            <artifactId>not-yet-implemented-maven-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    1. Add the plugin in the <build>section.
            <plugin>
                <groupId>com.pikodat</groupId>
                <artifactId>not-yet-implemented-maven-plugin</artifactId>
                <version>1.0-SNAPSHOT</version>
                <executions>
                    <execution>
                        <id>validation</id>
                        <goals>
                            <goal>check-not-yet-implemented</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <checkException>true</checkException>
                </configuration>
            </plugin>
  • Annotate your not implemented methods with @NotYetImplemented.
@NotYetImplemented
private List<DataPackage> readData() {
  //..
}

Now the maven plugin prints the following warning while packaging the application

[INFO] --- not-yet-implemented-maven-plugin:1.0-SNAPSHOT:check-not-yet-implemented (validation) @ partnerbase-depositor ---
[WARNING] Method "readData" in File "<path>/Demo.java" (Line: 117)is annotated with "@NotYetImplemented".
[INFO] ---------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ---------------------------------------------------------------
[INFO] Total time: 4.183s
[INFO] Finished at: Mon Sep 28 19:29:54 CEST 2015
[INFO] Final Memory: 24M/808M
[INFO] ---------------------------------------------------------------

Additional info for my IBM Notes Domino friends: The plugin is written in Java 8 (with the usage of streams) but can easily be ported to Java 6.