This always returns null on responses returned from {@link #cacheResponse}, {@link
* #networkResponse}, and {@link #priorResponse()}.
*/
- public ResponseBody body() {
+ public @Nullable ResponseBody body() {
return body;
}
@@ -200,7 +201,7 @@ public final class Response implements Closeable {
* the network, such as when the response is fully cached. The body of the returned response
* should not be read.
*/
- public Response networkResponse() {
+ public @Nullable Response networkResponse() {
return networkResponse;
}
@@ -209,7 +210,7 @@ public final class Response implements Closeable {
* cache. For conditional get requests the cache response and network response may both be
* non-null. The body of the returned response should not be read.
*/
- public Response cacheResponse() {
+ public @Nullable Response cacheResponse() {
return cacheResponse;
}
@@ -219,7 +220,7 @@ public final class Response implements Closeable {
* returned response should not be read because it has already been consumed by the redirecting
* client.
*/
- public Response priorResponse() {
+ public @Nullable Response priorResponse() {
return priorResponse;
}
@@ -290,7 +291,7 @@ public final class Response implements Closeable {
Protocol protocol;
int code = -1;
String message;
- Handshake handshake;
+ @Nullable Handshake handshake;
Headers.Builder headers;
ResponseBody body;
Response networkResponse;
@@ -338,7 +339,7 @@ public final class Response implements Closeable {
return this;
}
- public Builder handshake(Handshake handshake) {
+ public Builder handshake(@Nullable Handshake handshake) {
this.handshake = handshake;
return this;
}
@@ -372,18 +373,18 @@ public final class Response implements Closeable {
return this;
}
- public Builder body(ResponseBody body) {
+ public Builder body(@Nullable ResponseBody body) {
this.body = body;
return this;
}
- public Builder networkResponse(Response networkResponse) {
+ public Builder networkResponse(@Nullable Response networkResponse) {
if (networkResponse != null) checkSupportResponse("networkResponse", networkResponse);
this.networkResponse = networkResponse;
return this;
}
- public Builder cacheResponse(Response cacheResponse) {
+ public Builder cacheResponse(@Nullable Response cacheResponse) {
if (cacheResponse != null) checkSupportResponse("cacheResponse", cacheResponse);
this.cacheResponse = cacheResponse;
return this;
@@ -401,7 +402,7 @@ public final class Response implements Closeable {
}
}
- public Builder priorResponse(Response priorResponse) {
+ public Builder priorResponse(@Nullable Response priorResponse) {
if (priorResponse != null) checkPriorResponse(priorResponse);
this.priorResponse = priorResponse;
return this;
diff --git a/okhttp/src/main/java/okhttp3/ResponseBody.java b/okhttp/src/main/java/okhttp3/ResponseBody.java
index c00e90f96..17447f3d6 100644
--- a/okhttp/src/main/java/okhttp3/ResponseBody.java
+++ b/okhttp/src/main/java/okhttp3/ResponseBody.java
@@ -21,6 +21,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.charset.Charset;
+import javax.annotation.Nullable;
import okhttp3.internal.Util;
import okio.Buffer;
import okio.BufferedSource;
@@ -102,7 +103,7 @@ public abstract class ResponseBody implements Closeable {
/** Multiple calls to {@link #charStream()} must return the same instance. */
private Reader reader;
- public abstract MediaType contentType();
+ public abstract @Nullable MediaType contentType();
/**
* Returns the number of bytes in that will returned by {@link #bytes}, or {@link #byteStream}, or
@@ -190,7 +191,7 @@ public abstract class ResponseBody implements Closeable {
* Returns a new response body that transmits {@code content}. If {@code contentType} is non-null
* and lacks a charset, this will use UTF-8.
*/
- public static ResponseBody create(MediaType contentType, String content) {
+ public static ResponseBody create(@Nullable MediaType contentType, String content) {
Charset charset = UTF_8;
if (contentType != null) {
charset = contentType.charset();
@@ -204,17 +205,17 @@ public abstract class ResponseBody implements Closeable {
}
/** Returns a new response body that transmits {@code content}. */
- public static ResponseBody create(final MediaType contentType, byte[] content) {
+ public static ResponseBody create(final @Nullable MediaType contentType, byte[] content) {
Buffer buffer = new Buffer().write(content);
return create(contentType, content.length, buffer);
}
/** Returns a new response body that transmits {@code content}. */
- public static ResponseBody create(
- final MediaType contentType, final long contentLength, final BufferedSource content) {
+ public static ResponseBody create(final @Nullable MediaType contentType,
+ final long contentLength, final BufferedSource content) {
if (content == null) throw new NullPointerException("source == null");
return new ResponseBody() {
- @Override public MediaType contentType() {
+ @Override public @Nullable MediaType contentType() {
return contentType;
}
diff --git a/okhttp/src/main/java/okhttp3/Route.java b/okhttp/src/main/java/okhttp3/Route.java
index 7c7e9635e..14158673c 100644
--- a/okhttp/src/main/java/okhttp3/Route.java
+++ b/okhttp/src/main/java/okhttp3/Route.java
@@ -17,6 +17,7 @@ package okhttp3;
import java.net.InetSocketAddress;
import java.net.Proxy;
+import javax.annotation.Nullable;
/**
* The concrete route used by a connection to reach an abstract origin server. When creating a
@@ -79,14 +80,11 @@ public final class Route {
return address.sslSocketFactory != null && proxy.type() == Proxy.Type.HTTP;
}
- @Override public boolean equals(Object obj) {
- if (obj instanceof Route) {
- Route other = (Route) obj;
- return address.equals(other.address)
- && proxy.equals(other.proxy)
- && inetSocketAddress.equals(other.inetSocketAddress);
- }
- return false;
+ @Override public boolean equals(@Nullable Object other) {
+ return other instanceof Route
+ && ((Route) other).address.equals(address)
+ && ((Route) other).proxy.equals(proxy)
+ && ((Route) other).inetSocketAddress.equals(inetSocketAddress);
}
@Override public int hashCode() {
diff --git a/okhttp/src/main/java/okhttp3/WebSocket.java b/okhttp/src/main/java/okhttp3/WebSocket.java
index 12457e535..54cf6f402 100644
--- a/okhttp/src/main/java/okhttp3/WebSocket.java
+++ b/okhttp/src/main/java/okhttp3/WebSocket.java
@@ -15,6 +15,7 @@
*/
package okhttp3;
+import javax.annotation.Nullable;
import okio.ByteString;
/**
@@ -101,7 +102,7 @@ public interface WebSocket {
* href="http://tools.ietf.org/html/rfc6455#section-7.4">Section 7.4 of RFC 6455 or {@code 0}.
* @param reason Reason for shutting down or {@code null}.
*/
- boolean close(int code, String reason);
+ boolean close(int code, @Nullable String reason);
/**
* Immediately and violently release resources held by this web socket, discarding any enqueued
diff --git a/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.java b/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.java
index dae556bb9..410e8acbc 100644
--- a/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.java
+++ b/okhttp/src/main/java/okhttp3/internal/cache/CacheStrategy.java
@@ -16,6 +16,7 @@
package okhttp3.internal.cache;
import java.util.Date;
+import javax.annotation.Nullable;
import okhttp3.CacheControl;
import okhttp3.Headers;
import okhttp3.Request;
@@ -48,10 +49,10 @@ import static java.util.concurrent.TimeUnit.SECONDS;
*/
public final class CacheStrategy {
/** The request to send on the network, or null if this call doesn't use the network. */
- public final Request networkRequest;
+ public final @Nullable Request networkRequest;
/** The cached response to return or validate; or null if this call doesn't use a cache. */
- public final Response cacheResponse;
+ public final @Nullable Response cacheResponse;
CacheStrategy(Request networkRequest, Response cacheResponse) {
this.networkRequest = networkRequest;
diff --git a/okhttp/src/main/java/okhttp3/internal/cache/DiskLruCache.java b/okhttp/src/main/java/okhttp3/internal/cache/DiskLruCache.java
index 29a8ce0cf..c3fb740e2 100644
--- a/okhttp/src/main/java/okhttp3/internal/cache/DiskLruCache.java
+++ b/okhttp/src/main/java/okhttp3/internal/cache/DiskLruCache.java
@@ -32,6 +32,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.annotation.Nullable;
import okhttp3.internal.Util;
import okhttp3.internal.io.FileSystem;
import okhttp3.internal.platform.Platform;
@@ -454,7 +455,7 @@ public final class DiskLruCache implements Closeable, Flushable {
/**
* Returns an editor for the entry named {@code key}, or null if another edit is in progress.
*/
- public Editor edit(String key) throws IOException {
+ public @Nullable Editor edit(String key) throws IOException {
return edit(key, ANY_SEQUENCE_NUMBER);
}
@@ -805,7 +806,7 @@ public final class DiskLruCache implements Closeable, Flushable {
* Returns an editor for this snapshot's entry, or null if either the entry has changed since
* this snapshot was created or if another edit is in progress.
*/
- public Editor edit() throws IOException {
+ public @Nullable Editor edit() throws IOException {
return DiskLruCache.this.edit(key, sequenceNumber);
}
diff --git a/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.java b/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.java
index c6ee1ff8b..c5bc7d8b8 100644
--- a/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.java
+++ b/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.java
@@ -29,6 +29,7 @@ import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
+import javax.annotation.Nullable;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
@@ -378,7 +379,7 @@ public final class RealConnection extends Http2Connection.Listener implements Co
* Returns true if this connection can carry a stream allocation to {@code address}. If non-null
* {@code route} is the resolved route for a connection.
*/
- public boolean isEligible(Address address, Route route) {
+ public boolean isEligible(Address address, @Nullable Route route) {
// If this connection is not accepting new streams, we're done.
if (allocations.size() >= allocationLimit || noNewStreams) return false;
diff --git a/okhttp/src/main/java/okhttp3/package-info.java b/okhttp/src/main/java/okhttp3/package-info.java
new file mode 100644
index 000000000..a34c5bbf8
--- /dev/null
+++ b/okhttp/src/main/java/okhttp3/package-info.java
@@ -0,0 +1,3 @@
+/** An HTTP+HTTP/2 client for Android and Java applications. */
+@javax.annotation.ParametersAreNonnullByDefault
+package okhttp3;
diff --git a/pom.xml b/pom.xml
index 5cf1c539b..dea1a09fd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -87,6 +87,12 @@