Skip to content

Commit

Permalink
compile with Java 8 and enable Checker Framework
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Aug 22, 2015
1 parent 8c2678d commit 0839841
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 5 deletions.
34 changes: 29 additions & 5 deletions examples/javaee7/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- This property will be set by the Maven Dependency plugin -->
<annotatedJdk>${org.checkerframework:jdk8:jar}</annotatedJdk>
</properties>

<dependencies>
Expand Down Expand Up @@ -69,6 +71,21 @@
<version>7.0</version>
<scope>provided</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>
Expand All @@ -78,11 +95,17 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
<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>
<plugin>
Expand All @@ -102,6 +125,7 @@
<phase>validate</phase>
<goals>
<goal>copy</goal>
<goal>properties</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

@SuppressWarnings({"initialization.fields.uninitialized", "argument.type.incompatible"})
@Stateless
@Named
public class AddressBookServiceBean {
Expand All @@ -19,6 +20,7 @@ public class AddressBookServiceBean {
@PersistenceContext
private EntityManager em;

@SuppressWarnings("return.type.incompatible")
public Person find(long id) {
TypedQuery<Person> typedQuery = em.createQuery("SELECT OBJECT(o) FROM Person AS o WHERE o.id = :id", Person.class);
typedQuery.setParameter("id", id);
Expand All @@ -34,6 +36,7 @@ public List<Person> findAll() {
return typedQuery.getResultList();
}

@SuppressWarnings("return.type.incompatible")
public Person add(Person toPersist) {
Person persisted = null;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;

@SuppressWarnings("initialization.fields.uninitialized")
@Entity
public class Person implements Serializable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public static String getDisplayName(JsonObject body) throws ApiException {
return displayName;
}

@SuppressWarnings("return.type.incompatible")
public static String getPhoneNumber(JsonObject body) {
String keyForPhoneNumber = "phoneNumber";
JsonString phoneNumber = body.getJsonString(keyForPhoneNumber);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
import static javax.ws.rs.core.Response.Status.NOT_FOUND;

@SuppressWarnings("initialization.fields.uninitialized")
@Path("v1/people")
public class People {

Expand All @@ -40,6 +41,7 @@ public Response list() {
return Response.ok().entity(Json.createObjectBuilder().add("message", response).build()).type(MediaType.APPLICATION_JSON).build();
}

@SuppressWarnings({"argument.type.incompatible", "return.type.incompatible"})
@POST
public Response add(JsonObject body) {
String displayName;
Expand All @@ -59,6 +61,7 @@ public Response add(JsonObject body) {
return Response.ok().entity(ApiUtil.toJson(persistedPerson).build()).type(MediaType.APPLICATION_JSON).build();
}

@SuppressWarnings("argument.type.incompatible")
@PUT
@Path("{id}")
public Response edit(@PathParam("id") long idToEdit, JsonObject body) {
Expand All @@ -78,6 +81,7 @@ public Response edit(@PathParam("id") long idToEdit, JsonObject body) {
return Response.ok().entity(ApiUtil.toJson(saved).build()).type(MediaType.APPLICATION_JSON).build();
}

@SuppressWarnings("argument.type.incompatible")
private void blankOutSinceToPutIsToReplace(Person personToEdit) {
personToEdit.setDisplayName(null);
personToEdit.setPhoneNumber(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@SuppressWarnings("initialization.fields.uninitialized")
@ViewScoped
@Named
public class EditPage implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import javax.faces.view.ViewScoped;
import javax.inject.Named;

@SuppressWarnings("initialization.fields.uninitialized")
@ViewScoped
@Named
public class HomePage implements Serializable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public void testToJson() {
assertEquals(expResult.build(), result.build());
}

@SuppressWarnings("argument.type.incompatible")
@Test
public void testGetDisplayName() {
JsonObject body = Json.createObjectBuilder().add("id", 1l).build();
Expand All @@ -30,6 +31,7 @@ public void testGetDisplayName() {
}
}

@SuppressWarnings("argument.type.incompatible")
@Test
public void testGetPhoneNumberMissing() {
JsonObject body = Json.createObjectBuilder().add("id", 1l).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

public class PeopleIT {

@SuppressWarnings("argument.type.incompatible")
private static final Logger logger = Logger.getLogger(PeopleIT.class.getCanonicalName());

public PeopleIT() {
Expand Down Expand Up @@ -63,6 +64,7 @@ public void addAndDelete() {
logger.fine("added and deleted id " + id);
}

@SuppressWarnings("argument.type.incompatible")
@Test
public void addEditAndDelete() {
String displayNameKey = "displayName";
Expand Down

1 comment on commit 0839841

@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.

I switched this project to Java 8 in a branch because I haven't yet been able to figure out how to use Checker with Java 7: pdurbin/maven-hello-world#3

Please sign in to comment.