Skip to content

Commit

Permalink
enable checker framework. thanks @renatoathaydes !
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 21, 2015
1 parent 8a6b508 commit 3c08628
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
50 changes: 50 additions & 0 deletions my-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,34 @@
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>

<properties>
<!-- This property will be set by the Maven Dependency plugin -->
<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>checker-qual</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.checkerframework</groupId>
<artifactId>jdk8</artifactId>
<version>1.9.4</version>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down Expand Up @@ -55,6 +76,35 @@
</execution>
</executions>
</plugin>
<plugin>
<!-- This plugin will set the properties values using dependency information -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<goals>
<goal>properties</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<fork>true</fork>
<!-- Add all the checkers you want to enable here -->
<annotationProcessors>
<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>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
16 changes: 16 additions & 0 deletions my-app/src/main/java/com/mycompany/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,21 @@ public class App
public static void main( String[] args )
{
System.out.println( "Hello World!" );

System.out.println("A NullPointerException is a drag...");
Object myObject = null;
/**
* Checker prevents this from compiling...
*/
// System.out.println("myObject: " + myObject.toString());
/**
* ... which is simply fantastic. It shows:
*
* error: [dereference.of.nullable] dereference of possibly-null
* reference myObject
*
* http://checkerframework.org
*/
System.out.println("... but thankfully, Checker has our back: http://checkerframework.org");
}
}

2 comments on commit 3c08628

@renatoathaydes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're welcome! Trying to get the instructions I wrote merged into the checker repo so it becomes the official documentation for Maven.

@pdurbin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@renatoathaydes great! Did you see issue #3 (Checker not working on Java 7) I opened on this repo?

Please sign in to comment.