Adam Warski

4 Feb 2009

JSR308 Checkers Maven2 plugin

java
static analysis

I’ve written a prototype JSR308 Checkers Maven2 plugin. You can use the plugin to run any checker on the sources of your module(s).

The JSR308 compiler, and in effect also the checkers, are run in a separate, forked, JVM process. Additionally, this process only does the processing, without actual compilation. So all of your files will be compiled by the same javac as before. The plugin only runs the additional verification of the source code, and will not affect the produced bytecode. Java6 is required to run the forked JVM.

You can easily try using the standard checkers, for checking nullness, interning and mutability errors, as well as the typestate checker; I’ve uploaded the necessary jars to my repository, so to use any of them, you’ll need first to add repositories to your pom.xml:

<repositories>
    <repository>
        <id>mamut-releases</id>
        <url>http://repository.mamut.net.pl/content/repositories/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>mamut-releases</id>
        <url>http://repository.mamut.net.pl/content/repositories/releases</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>        
</pluginRepositories>

Then, to use the annotations used by the standard checkers, you’ll have to declare a dependency:

<dependencies>
    <!-- annotations for the standard checkers: nullness, interning, mutability -->
    <dependency>
        <groupId>mamut.net.pl</groupId>
        <artifactId>checkers-quals</artifactId>
        <version>0.8.6</version>
    </dependency>
    

<!-- and if you want to use the typestate checker: -->
    <dependency>
        <groupId>mamut.net.pl</groupId>
        <artifactId>typestate-checker</artifactId>
        <version>0.1</version>
    </dependency>
    

<!-- other dependencies -->
</dependencies>

And finally, you need to attach the plugin to your build lifecycle:

<build>
    <plugins>
        <plugin>
            <groupId>mamut.net.pl</groupId>
            <artifactId>checkersplugin</artifactId>
            <version>0.1</version>
            <executions>
                <execution>
                    <!-- run the checkers after compilation; this can also be any later phase -->
                    <phase>process-classes</phase>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                

<!-- checkers you want to be run -->
                <processors>
                    <processor>checkers.nullness.NullnessChecker</processor>
                    <processor>checkers.interning.InterningChecker</processor>
                    <processor>checkers.typestate.TypestateChecker</processor>
                </processors>
                

<!-- other configuration - see webpage for details -->
            </configuration>
        </plugin>
    </plugins>
</build>

And that’s it! After compiling, the specified checkers (annotations processors) will be run on your source code and report any errors found.

For more information and full configuration options description, see the web page: http://www.warski.org/checkersplugin.html

Waiting for feedback :)

Adam

comments powered by Disqus

Any questions?

Can’t find the answer you’re looking for?