diff --git a/pom.xml b/pom.xml
index 048bc44678..b48684c8f6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,6 +76,12 @@
okio
1.11.0
+
+ com.google.code.findbugs
+ jsr305
+ 3.0.2
+ provided
+
com.google.code.gson
gson
diff --git a/wire-gson-support/pom.xml b/wire-gson-support/pom.xml
index bb737aa591..7f58385896 100644
--- a/wire-gson-support/pom.xml
+++ b/wire-gson-support/pom.xml
@@ -21,7 +21,11 @@
com.google.code.gson
gson
-
+
+ com.google.code.findbugs
+ jsr305
+ provided
+
junit
junit
diff --git a/wire-gson-support/src/main/java/com/squareup/wire/ByteStringTypeAdapter.java b/wire-gson-support/src/main/java/com/squareup/wire/ByteStringTypeAdapter.java
index 7b51eaff1f..1fcc0f46ea 100644
--- a/wire-gson-support/src/main/java/com/squareup/wire/ByteStringTypeAdapter.java
+++ b/wire-gson-support/src/main/java/com/squareup/wire/ByteStringTypeAdapter.java
@@ -20,6 +20,7 @@
import com.google.gson.stream.JsonToken;
import com.google.gson.stream.JsonWriter;
import java.io.IOException;
+import javax.annotation.Nullable;
import okio.ByteString;
/**
@@ -29,7 +30,7 @@
*/
class ByteStringTypeAdapter extends TypeAdapter {
- @Override public void write(JsonWriter out, ByteString value) throws IOException {
+ @Override public void write(JsonWriter out, @Nullable ByteString value) throws IOException {
if (value == null) {
out.nullValue();
} else {
@@ -37,7 +38,7 @@ class ByteStringTypeAdapter extends TypeAdapter {
}
}
- @Override public ByteString read(JsonReader in) throws IOException {
+ @Override public @Nullable ByteString read(JsonReader in) throws IOException {
if (in.peek() == JsonToken.NULL) {
in.nextNull();
return null;
diff --git a/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.java b/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.java
index 741026e76b..27069769f2 100644
--- a/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.java
+++ b/wire-gson-support/src/main/java/com/squareup/wire/MessageTypeAdapter.java
@@ -31,6 +31,7 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import javax.annotation.Nullable;
import static com.squareup.wire.WireField.Label;
import static java.util.Collections.unmodifiableMap;
@@ -58,7 +59,7 @@ class MessageTypeAdapter, B extends Message.Builder TypeAdapter create(Gson gson, TypeToken type) {
+ @Override public @Nullable TypeAdapter create(Gson gson, TypeToken type) {
if (type.getRawType().equals(ByteString.class)) {
return (TypeAdapter) new ByteStringTypeAdapter();
}
diff --git a/wire-gson-support/src/main/java/com/squareup/wire/package-info.java b/wire-gson-support/src/main/java/com/squareup/wire/package-info.java
new file mode 100644
index 0000000000..f4c17a1a39
--- /dev/null
+++ b/wire-gson-support/src/main/java/com/squareup/wire/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Wire JSON encoding via Gson.
+ */
+@javax.annotation.ParametersAreNonnullByDefault
+package com.squareup.wire;
diff --git a/wire-runtime/pom.xml b/wire-runtime/pom.xml
index 8c65195c4c..ecde3d2256 100644
--- a/wire-runtime/pom.xml
+++ b/wire-runtime/pom.xml
@@ -16,13 +16,16 @@
com.squareup.okio
okio
-
com.google.android
android
provided
-
+
+ com.google.code.findbugs
+ jsr305
+ provided
+
junit
junit
diff --git a/wire-runtime/src/main/java/com/squareup/wire/EnumAdapter.java b/wire-runtime/src/main/java/com/squareup/wire/EnumAdapter.java
index 92d7826a5a..3ae33a4dff 100644
--- a/wire-runtime/src/main/java/com/squareup/wire/EnumAdapter.java
+++ b/wire-runtime/src/main/java/com/squareup/wire/EnumAdapter.java
@@ -16,6 +16,7 @@
package com.squareup.wire;
import java.io.IOException;
+import javax.annotation.Nullable;
/**
* An abstract {@link ProtoAdapter} that converts values of an enum to and from integers.
@@ -46,5 +47,5 @@ protected EnumAdapter(Class type) {
* Converts an integer to an enum.
* Returns null if there is no corresponding enum.
*/
- protected abstract E fromValue(int value);
+ protected abstract @Nullable E fromValue(int value);
}
diff --git a/wire-runtime/src/main/java/com/squareup/wire/Message.java b/wire-runtime/src/main/java/com/squareup/wire/Message.java
index 147db1a161..7635016a86 100644
--- a/wire-runtime/src/main/java/com/squareup/wire/Message.java
+++ b/wire-runtime/src/main/java/com/squareup/wire/Message.java
@@ -19,6 +19,7 @@
import java.io.ObjectStreamException;
import java.io.OutputStream;
import java.io.Serializable;
+import javax.annotation.Nullable;
import okio.Buffer;
import okio.BufferedSink;
import okio.ByteString;
@@ -114,7 +115,7 @@ public abstract static class Builder, B extends Builder<
* {@link #buildUnknownFields()}. It's automatically cleared in {@link #buildUnknownFields()},
* and can also be manually cleared by calling {@link #clearUnknownFields()}.
*/
- transient Buffer unknownFieldsBuffer;
+ transient @Nullable Buffer unknownFieldsBuffer;
transient ProtoWriter unknownFieldsWriter;
protected Builder() {
@@ -132,7 +133,8 @@ public final Builder addUnknownFields(ByteString unknownFields) {
return this;
}
- public final Builder addUnknownField(int tag, FieldEncoding fieldEncoding, Object value) {
+ public final Builder addUnknownField(
+ int tag, FieldEncoding fieldEncoding, @Nullable Object value) {
prepareForNewUnknownFields();
try {
ProtoAdapter