mercredi 19 avril 2017

The Checker Framework


The Checker Framework enhances Java’s type system to make it more powerful and useful. This lets software developers detect and prevent errors in their Java programs. The frameWork comes with a nice feature Nullness Checker that detect NullPointerException at compiletime


For Maven Project, just add the following depencies & plugin in the pom.xml
      
<dependencies> <!-- annotations from the Checker Framework: nullness, interning, locking, ... --> <dependency> <groupId>org.checkerframework</groupId> <artifactId>checker-qual</artifactId> <version>2.1.10</version> </dependency> <dependency> <groupId>org.checkerframework</groupId> <artifactId>checker</artifactId> <version>2.1.10</version> </dependency> <!-- The Type Annotations compiler. Uncomment if using Java 7 or annotations in comments. --> <!-- <dependency> <groupId>org.checkerframework</groupId> <artifactId>compiler</artifactId> <version>2.1.10</version> </dependency> --> <!-- The annotated JDK to use (change to jdk7 if using Java 7). --> <dependency> <groupId>org.checkerframework</groupId> <artifactId>jdk8</artifactId> <version>2.1.10</version> </dependency> </dependencies>

 <plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.1</version>
    <configuration>
        <!-- Change source and target to 1.7 if using Java 7 -->
        <source>1.8</source>
        <target>1.8</target>
        <fork>true</fork>
        <annotationProcessors>
           <!-- Add all the checkers you want to enable here -->
           <annotationProcessor>
              org.checkerframework.checker.nullness.NullnessChecker
           </annotationProcessor>
        </annotationProcessors>
        <compilerArgs>
             <!-- location of the annotated JDK, which comes from a Maven dependency -->
             <arg>-Xbootclasspath/p:${annotatedJdk}</arg>
             <!-- Uncomment the following line to use the type annotations compiler. -->
             <arg>-J-Xbootclasspath/p:${typeAnnotationsJavac}</arg> 
        </compilerArgs>
    </configuration>
 </plugin>



For more details : https://checkerframework.org/manual/



That's all :-)



Aucun commentaire:

Enregistrer un commentaire