mirror of
https://github.com/square/okhttp.git
synced 2025-07-31 05:04:26 +03:00
EverythingIsNonNull annotation (#4286)
Adds an annotation EverythingIsNonNull, and fixes some nullability on public API.
This commit is contained in:
@ -1,3 +1,3 @@
|
|||||||
/** A DNS over HTTPS implementation for OkHttp. */
|
/** A DNS over HTTPS implementation for OkHttp. */
|
||||||
@javax.annotation.ParametersAreNonnullByDefault
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
package okhttp3.dnsoverhttps;
|
package okhttp3.dnsoverhttps;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
/** An OkHttp interceptor which logs HTTP request and response data. */
|
/** An OkHttp interceptor which logs HTTP request and response data. */
|
||||||
@javax.annotation.ParametersAreNonnullByDefault
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
package okhttp3.logging;
|
package okhttp3.logging;
|
||||||
|
@ -35,7 +35,7 @@ public final class RealEventSource
|
|||||||
private final Request request;
|
private final Request request;
|
||||||
private final EventSourceListener listener;
|
private final EventSourceListener listener;
|
||||||
|
|
||||||
private Call call;
|
private @Nullable Call call;
|
||||||
|
|
||||||
public RealEventSource(Request request, EventSourceListener listener) {
|
public RealEventSource(Request request, EventSourceListener listener) {
|
||||||
this.request = request;
|
this.request = request;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
/** Private support classes for server-sent events. */
|
/** Private support classes for server-sent events. */
|
||||||
@javax.annotation.ParametersAreNonnullByDefault
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
package okhttp3.internal.sse;
|
package okhttp3.internal.sse;
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
/** Support for server-sent events. */
|
/** Support for server-sent events. */
|
||||||
@javax.annotation.ParametersAreNonnullByDefault
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
package okhttp3.sse;
|
package okhttp3.sse;
|
||||||
|
@ -49,7 +49,7 @@ public final class EventSourceRecorder extends EventSourceListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(EventSource eventSource, Throwable t, @Nullable Response response) {
|
public void onFailure(EventSource eventSource, @Nullable Throwable t, @Nullable Response response) {
|
||||||
Platform.get().log(Platform.INFO, "[ES] onFailure", t);
|
Platform.get().log(Platform.INFO, "[ES] onFailure", t);
|
||||||
events.add(new Failure(t, response));
|
events.add(new Failure(t, response));
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import java.security.cert.X509Certificate;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.net.ssl.KeyManager;
|
import javax.net.ssl.KeyManager;
|
||||||
import javax.net.ssl.SSLContext;
|
import javax.net.ssl.SSLContext;
|
||||||
import javax.net.ssl.SSLSocketFactory;
|
import javax.net.ssl.SSLSocketFactory;
|
||||||
@ -110,8 +111,8 @@ public final class HandshakeCertificates {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
private HeldCertificate heldCertificate;
|
private @Nullable HeldCertificate heldCertificate;
|
||||||
private X509Certificate[] intermediates;
|
private @Nullable X509Certificate[] intermediates;
|
||||||
|
|
||||||
private final List<X509Certificate> trustedCertificates = new ArrayList<>();
|
private final List<X509Certificate> trustedCertificates = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -32,6 +32,7 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import javax.security.auth.x500.X500Principal;
|
import javax.security.auth.x500.X500Principal;
|
||||||
import okio.ByteString;
|
import okio.ByteString;
|
||||||
import org.bouncycastle.asn1.ASN1Encodable;
|
import org.bouncycastle.asn1.ASN1Encodable;
|
||||||
@ -203,14 +204,14 @@ public final class HeldCertificate {
|
|||||||
|
|
||||||
private long notBefore = -1L;
|
private long notBefore = -1L;
|
||||||
private long notAfter = -1L;
|
private long notAfter = -1L;
|
||||||
private String cn;
|
private @Nullable String cn;
|
||||||
private String ou;
|
private @Nullable String ou;
|
||||||
private final List<String> altNames = new ArrayList<>();
|
private final List<String> altNames = new ArrayList<>();
|
||||||
private BigInteger serialNumber;
|
private @Nullable BigInteger serialNumber;
|
||||||
private KeyPair keyPair;
|
private @Nullable KeyPair keyPair;
|
||||||
private HeldCertificate signedBy;
|
private @Nullable HeldCertificate signedBy;
|
||||||
private int maxIntermediateCas = -1;
|
private int maxIntermediateCas = -1;
|
||||||
private String keyAlgorithm;
|
private @Nullable String keyAlgorithm;
|
||||||
private int keySize;
|
private int keySize;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
|
3
okhttp-tls/src/main/java/okhttp3/tls/package-info.java
Normal file
3
okhttp-tls/src/main/java/okhttp3/tls/package-info.java
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
/** OkHttp Transport Layer Security (TLS) library. */
|
||||||
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
|
package okhttp3.tls;
|
@ -0,0 +1,3 @@
|
|||||||
|
/** Support for JDK provider APIs. */
|
||||||
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
|
package okhttp3;
|
@ -62,7 +62,7 @@ import javax.annotation.Nullable;
|
|||||||
public interface Authenticator {
|
public interface Authenticator {
|
||||||
/** An authenticator that knows no credentials and makes no attempt to authenticate. */
|
/** An authenticator that knows no credentials and makes no attempt to authenticate. */
|
||||||
Authenticator NONE = new Authenticator() {
|
Authenticator NONE = new Authenticator() {
|
||||||
@Override public Request authenticate(Route route, Response response) {
|
@Override public Request authenticate(@Nullable Route route, Response response) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -458,10 +458,10 @@ public final class Cookie {
|
|||||||
* #domain() domain} values must all be set before calling {@link #build}.
|
* #domain() domain} values must all be set before calling {@link #build}.
|
||||||
*/
|
*/
|
||||||
public static final class Builder {
|
public static final class Builder {
|
||||||
String name;
|
@Nullable String name;
|
||||||
String value;
|
@Nullable String value;
|
||||||
long expiresAt = HttpDate.MAX_DATE;
|
long expiresAt = HttpDate.MAX_DATE;
|
||||||
String domain;
|
@Nullable String domain;
|
||||||
String path = "/";
|
String path = "/";
|
||||||
boolean secure;
|
boolean secure;
|
||||||
boolean httpOnly;
|
boolean httpOnly;
|
||||||
|
@ -18,6 +18,7 @@ package okhttp3;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.annotation.Nullable;
|
||||||
import okhttp3.internal.NamedRunnable;
|
import okhttp3.internal.NamedRunnable;
|
||||||
import okhttp3.internal.cache.CacheInterceptor;
|
import okhttp3.internal.cache.CacheInterceptor;
|
||||||
import okhttp3.internal.connection.ConnectInterceptor;
|
import okhttp3.internal.connection.ConnectInterceptor;
|
||||||
@ -38,7 +39,7 @@ final class RealCall implements Call {
|
|||||||
* There is a cycle between the {@link Call} and {@link EventListener} that makes this awkward.
|
* There is a cycle between the {@link Call} and {@link EventListener} that makes this awkward.
|
||||||
* This will be set after we create the call instance then create the event listener instance.
|
* This will be set after we create the call instance then create the event listener instance.
|
||||||
*/
|
*/
|
||||||
private EventListener eventListener;
|
private @Nullable EventListener eventListener;
|
||||||
|
|
||||||
/** The application's original request unadulterated by redirects or auth headers. */
|
/** The application's original request unadulterated by redirects or auth headers. */
|
||||||
final Request originalRequest;
|
final Request originalRequest;
|
||||||
|
@ -35,7 +35,7 @@ public final class Request {
|
|||||||
final @Nullable RequestBody body;
|
final @Nullable RequestBody body;
|
||||||
final Map<Class<?>, Object> tags;
|
final Map<Class<?>, Object> tags;
|
||||||
|
|
||||||
private volatile CacheControl cacheControl; // Lazily initialized.
|
private volatile @Nullable CacheControl cacheControl; // Lazily initialized.
|
||||||
|
|
||||||
Request(Builder builder) {
|
Request(Builder builder) {
|
||||||
this.url = builder.url;
|
this.url = builder.url;
|
||||||
@ -117,10 +117,10 @@ public final class Request {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
HttpUrl url;
|
@Nullable HttpUrl url;
|
||||||
String method;
|
String method;
|
||||||
Headers.Builder headers;
|
Headers.Builder headers;
|
||||||
RequestBody body;
|
@Nullable RequestBody body;
|
||||||
|
|
||||||
/** A mutable map of tags, or an immutable empty map if we don't have any. */
|
/** A mutable map of tags, or an immutable empty map if we don't have any. */
|
||||||
Map<Class<?>, Object> tags = Collections.emptyMap();
|
Map<Class<?>, Object> tags = Collections.emptyMap();
|
||||||
|
@ -54,7 +54,7 @@ public final class Response implements Closeable {
|
|||||||
final long sentRequestAtMillis;
|
final long sentRequestAtMillis;
|
||||||
final long receivedResponseAtMillis;
|
final long receivedResponseAtMillis;
|
||||||
|
|
||||||
private volatile CacheControl cacheControl; // Lazily initialized.
|
private volatile @Nullable CacheControl cacheControl; // Lazily initialized.
|
||||||
|
|
||||||
Response(Builder builder) {
|
Response(Builder builder) {
|
||||||
this.request = builder.request;
|
this.request = builder.request;
|
||||||
@ -302,16 +302,16 @@ public final class Response implements Closeable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
Request request;
|
@Nullable Request request;
|
||||||
Protocol protocol;
|
@Nullable Protocol protocol;
|
||||||
int code = -1;
|
int code = -1;
|
||||||
String message;
|
String message;
|
||||||
@Nullable Handshake handshake;
|
@Nullable Handshake handshake;
|
||||||
Headers.Builder headers;
|
Headers.Builder headers;
|
||||||
ResponseBody body;
|
@Nullable ResponseBody body;
|
||||||
Response networkResponse;
|
@Nullable Response networkResponse;
|
||||||
Response cacheResponse;
|
@Nullable Response cacheResponse;
|
||||||
Response priorResponse;
|
@Nullable Response priorResponse;
|
||||||
long sentRequestAtMillis;
|
long sentRequestAtMillis;
|
||||||
long receivedResponseAtMillis;
|
long receivedResponseAtMillis;
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ import static okhttp3.internal.Util.UTF_8;
|
|||||||
*/
|
*/
|
||||||
public abstract class ResponseBody implements Closeable {
|
public abstract class ResponseBody implements Closeable {
|
||||||
/** Multiple calls to {@link #charStream()} must return the same instance. */
|
/** Multiple calls to {@link #charStream()} must return the same instance. */
|
||||||
private Reader reader;
|
private @Nullable Reader reader;
|
||||||
|
|
||||||
public abstract @Nullable MediaType contentType();
|
public abstract @Nullable MediaType contentType();
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ public abstract class ResponseBody implements Closeable {
|
|||||||
private final Charset charset;
|
private final Charset charset;
|
||||||
|
|
||||||
private boolean closed;
|
private boolean closed;
|
||||||
private Reader delegate;
|
private @Nullable Reader delegate;
|
||||||
|
|
||||||
BomAwareReader(BufferedSource source, Charset charset) {
|
BomAwareReader(BufferedSource source, Charset charset) {
|
||||||
this.source = source;
|
this.source = source;
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2018 Square, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package okhttp3.internal.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Documented;
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.meta.TypeQualifierDefault;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends {@code ParametersAreNonnullByDefault} to also apply to Method results and fields.
|
||||||
|
*
|
||||||
|
* @see javax.annotation.ParametersAreNonnullByDefault
|
||||||
|
*/
|
||||||
|
@Documented
|
||||||
|
@Nonnull
|
||||||
|
@TypeQualifierDefault({
|
||||||
|
ElementType.FIELD,
|
||||||
|
ElementType.METHOD,
|
||||||
|
ElementType.PARAMETER
|
||||||
|
})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface EverythingIsNonNull { }
|
@ -1,3 +1,3 @@
|
|||||||
/** An HTTP+HTTP/2 client for Android and Java applications. */
|
/** An HTTP+HTTP/2 client for Android and Java applications. */
|
||||||
@javax.annotation.ParametersAreNonnullByDefault
|
@okhttp3.internal.annotations.EverythingIsNonNull
|
||||||
package okhttp3;
|
package okhttp3;
|
||||||
|
Reference in New Issue
Block a user