Skip to content

Commit

Permalink
Add JSR 305 nullability annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed May 8, 2017
1 parent 77f37fa commit 3c963a4
Show file tree
Hide file tree
Showing 53 changed files with 269 additions and 95 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,11 @@
<artifactId>moshi</artifactId>
<version>${moshi.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
5 changes: 5 additions & 0 deletions retrofit-adapters/guava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.adapter.guava;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-adapters/java8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<artifactId>retrofit</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.adapter.java8;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-adapters/rxjava/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>io.reactivex</groupId>
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@
package retrofit2.adapter.rxjava;

import java.io.IOException;
import javax.annotation.Nullable;
import retrofit2.Response;

/** The result of executing an HTTP request. */
public final class Result<T> {
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static <T> Result<T> error(Throwable error) {
if (error == null) throw new NullPointerException("error == null");
return new Result<>(null, error);
}

@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static <T> Result<T> response(Response<T> response) {
if (response == null) throw new NullPointerException("response == null");
return new Result<>(response, null);
}

private final Response<T> response;
private final Throwable error;
private final @Nullable Response<T> response;
private final @Nullable Throwable error;

private Result(Response<T> response, Throwable error) {
private Result(@Nullable Response<T> response, @Nullable Throwable error) {
this.response = response;
this.error = error;
}
Expand All @@ -42,7 +45,7 @@ private Result(Response<T> response, Throwable error) {
* The response received from executing an HTTP request. Only present when {@link #isError()} is
* false, null otherwise.
*/
public Response<T> response() {
public @Nullable Response<T> response() {
return response;
}

Expand All @@ -54,7 +57,7 @@ public Response<T> response() {
* remote server. Any other exception type indicates an unexpected failure and should be
* considered fatal (configuration error, programming error, etc.).
*/
public Throwable error() {
public @Nullable Throwable error() {
return error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package retrofit2.adapter.rxjava;

import java.lang.reflect.Type;
import javax.annotation.Nullable;
import retrofit2.Call;
import retrofit2.CallAdapter;
import retrofit2.Response;
Expand All @@ -25,15 +26,15 @@

final class RxJavaCallAdapter<R> implements CallAdapter<R, Object> {
private final Type responseType;
private final Scheduler scheduler;
private final @Nullable Scheduler scheduler;
private final boolean isAsync;
private final boolean isResult;
private final boolean isBody;
private final boolean isSingle;
private final boolean isCompletable;

RxJavaCallAdapter(Type responseType, Scheduler scheduler, boolean isAsync, boolean isResult,
boolean isBody, boolean isSingle, boolean isCompletable) {
RxJavaCallAdapter(Type responseType, @Nullable Scheduler scheduler, boolean isAsync,
boolean isResult, boolean isBody, boolean isSingle, boolean isCompletable) {
this.responseType = responseType;
this.scheduler = scheduler;
this.isAsync = isAsync;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import javax.annotation.Nullable;
import retrofit2.CallAdapter;
import retrofit2.HttpException;
import retrofit2.Response;
Expand Down Expand Up @@ -77,15 +78,16 @@ public static RxJavaCallAdapterFactory createAsync() {
* Returns an instance which creates synchronous observables that
* {@linkplain Observable#subscribeOn(Scheduler) subscribe on} {@code scheduler} by default.
*/
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static RxJavaCallAdapterFactory createWithScheduler(Scheduler scheduler) {
if (scheduler == null) throw new NullPointerException("scheduler == null");
return new RxJavaCallAdapterFactory(scheduler, false);
}

private final Scheduler scheduler;
private final @Nullable Scheduler scheduler;
private final boolean isAsync;

private RxJavaCallAdapterFactory(Scheduler scheduler, boolean isAsync) {
private RxJavaCallAdapterFactory(@Nullable Scheduler scheduler, boolean isAsync) {
this.scheduler = scheduler;
this.isAsync = isAsync;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.adapter.rxjava;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-adapters/rxjava2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>io.reactivex.rxjava2</groupId>
<artifactId>rxjava</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,27 @@
package retrofit2.adapter.rxjava2;

import java.io.IOException;
import javax.annotation.Nullable;
import retrofit2.Response;

/** The result of executing an HTTP request. */
public final class Result<T> {
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static <T> Result<T> error(Throwable error) {
if (error == null) throw new NullPointerException("error == null");
return new Result<>(null, error);
}

@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static <T> Result<T> response(Response<T> response) {
if (response == null) throw new NullPointerException("response == null");
return new Result<>(response, null);
}

private final Response<T> response;
private final Throwable error;
private final @Nullable Response<T> response;
private final @Nullable Throwable error;

private Result(Response<T> response, Throwable error) {
private Result(@Nullable Response<T> response, @Nullable Throwable error) {
this.response = response;
this.error = error;
}
Expand All @@ -42,7 +45,7 @@ private Result(Response<T> response, Throwable error) {
* The response received from executing an HTTP request. Only present when {@link #isError()} is
* false, null otherwise.
*/
public Response<T> response() {
public @Nullable Response<T> response() {
return response;
}

Expand All @@ -54,7 +57,7 @@ public Response<T> response() {
* remote server. Any other exception type indicates an unexpected failure and should be
* considered fatal (configuration error, programming error, etc.).
*/
public Throwable error() {
public @Nullable Throwable error() {
return error;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import java.lang.reflect.Type;
import javax.annotation.Nullable;
import retrofit2.Call;
import retrofit2.CallAdapter;
import retrofit2.Response;

final class RxJava2CallAdapter<R> implements CallAdapter<R, Object> {
private final Type responseType;
private final Scheduler scheduler;
private final @Nullable Scheduler scheduler;
private final boolean isAsync;
private final boolean isResult;
private final boolean isBody;
Expand All @@ -34,8 +35,8 @@ final class RxJava2CallAdapter<R> implements CallAdapter<R, Object> {
private final boolean isMaybe;
private final boolean isCompletable;

RxJava2CallAdapter(Type responseType, Scheduler scheduler, boolean isAsync, boolean isResult,
boolean isBody, boolean isFlowable, boolean isSingle, boolean isMaybe,
RxJava2CallAdapter(Type responseType, @Nullable Scheduler scheduler, boolean isAsync,
boolean isResult, boolean isBody, boolean isFlowable, boolean isSingle, boolean isMaybe,
boolean isCompletable) {
this.responseType = responseType;
this.scheduler = scheduler;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import javax.annotation.Nullable;
import retrofit2.CallAdapter;
import retrofit2.HttpException;
import retrofit2.Response;
Expand Down Expand Up @@ -75,15 +76,16 @@ public static RxJava2CallAdapterFactory createAsync() {
* Returns an instance which creates synchronous observables that
* {@linkplain Observable#subscribeOn(Scheduler) subscribe on} {@code scheduler} by default.
*/
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static RxJava2CallAdapterFactory createWithScheduler(Scheduler scheduler) {
if (scheduler == null) throw new NullPointerException("scheduler == null");
return new RxJava2CallAdapterFactory(scheduler, false);
}

private final Scheduler scheduler;
private final @Nullable Scheduler scheduler;
private final boolean isAsync;

private RxJava2CallAdapterFactory(Scheduler scheduler, boolean isAsync) {
private RxJava2CallAdapterFactory(@Nullable Scheduler scheduler, boolean isAsync) {
this.scheduler = scheduler;
this.isAsync = isAsync;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.adapter.rxjava2;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-converters/gson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ public static GsonConverterFactory create() {
* Create an instance using {@code gson} for conversion. Encoding to JSON and
* decoding from JSON (when no charset is specified by a header) will use UTF-8.
*/
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static GsonConverterFactory create(Gson gson) {
if (gson == null) throw new NullPointerException("gson == null");
return new GsonConverterFactory(gson);
}

private final Gson gson;

private GsonConverterFactory(Gson gson) {
if (gson == null) throw new NullPointerException("gson == null");
this.gson = gson;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.converter.gson;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-converters/jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public static JacksonConverterFactory create() {
}

/** Create an instance using {@code mapper} for conversion. */
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static JacksonConverterFactory create(ObjectMapper mapper) {
if (mapper == null) throw new NullPointerException("mapper == null");
return new JacksonConverterFactory(mapper);
}

private final ObjectMapper mapper;

private JacksonConverterFactory(ObjectMapper mapper) {
if (mapper == null) throw new NullPointerException("mapper == null");
this.mapper = mapper;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.converter.jackson;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-converters/moshi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>com.squareup.moshi</groupId>
<artifactId>moshi</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static MoshiConverterFactory create() {
}

/** Create an instance using {@code moshi} for conversion. */
@SuppressWarnings("ConstantConditions") // Guarding public API nullability.
public static MoshiConverterFactory create(Moshi moshi) {
if (moshi == null) throw new NullPointerException("moshi == null");
return new MoshiConverterFactory(moshi, false, false, false);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@ParametersAreNonnullByDefault
package retrofit2.converter.moshi;

import javax.annotation.ParametersAreNonnullByDefault;
5 changes: 5 additions & 0 deletions retrofit-converters/protobuf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
Expand Down
Loading

0 comments on commit 3c963a4

Please sign in to comment.