Skip to content

Commit

Permalink
Apply NullAway
Browse files Browse the repository at this point in the history
Motivation:

Before adopting NullAway(line#1680) or other static analysis tools.
Manually run it and clean up errors.

Modifications:

- Fix all true positives reported by NullAway

Result:

Less NullAway errors
  • Loading branch information
ikhoon committed Jun 5, 2020
1 parent 9716098 commit e029800
Show file tree
Hide file tree
Showing 41 changed files with 86 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id 'com.google.osdetector' version '1.6.2' apply false
// If you want to change `org.jetbrains.kotlin.jvm` version,
// If you want to change `org.jetbrains.kotlin.jvm` version,
// you also need to change `org.jetbrains.kotlin:kotlin-allopen` version in `dependencies.yml`.
id 'org.jetbrains.kotlin.jvm' version '1.3.72' apply false
}
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/com/linecorp/armeria/client/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

import static java.util.Objects.requireNonNull;

import javax.annotation.Nullable;

import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.common.Request;
Expand Down Expand Up @@ -71,6 +73,7 @@ public interface Client<I extends Request, O extends Response> extends Unwrappab
* @see ClientFactory#unwrap(Object, Class)
* @see Unwrappable
*/
@Nullable
@Override
default <T> T as(Class<T> type) {
requireNonNull(type, "type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ public ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpReques
return delegate().newDerivedContext(id, req, rpcReq, endpoint);
}

@Nullable
@Override
public EndpointGroup endpointGroup() {
return delegate().endpointGroup();
}

@Nullable
@Override
public Endpoint endpoint() {
return delegate().endpoint();
}

@Nullable
@Override
public String fragment() {
return delegate().fragment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ public Object newClient(ClientBuilderParams params) {
return delegate().newClient(params);
}

@Nullable
@Override
public <T> ClientBuilderParams clientBuilderParams(T client) {
return delegate().clientBuilderParams(client);
}

@Nullable
@Override
public <T> T unwrap(Object client, Class<T> type) {
return delegate().unwrap(client, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ public Object newClient(ClientBuilderParams params) {
return factory.newClient(params);
}

@Nullable
@Override
public <T> T unwrap(Object client, Class<T> type) {
final T params = ClientFactory.super.unwrap(client, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,13 @@ public ClientOptions options() {

@Override
public EndpointGroup endpointGroup() {
checkState(endpointGroup != null, "Should call init(endpoint) before invoking this method.");
return endpointGroup;
}

@Override
public Endpoint endpoint() {
checkState(endpoint != null, "Should call init(endpoint) before invoking this method.");
return endpoint;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ final class HttpSessionHandler extends ChannelDuplexHandler implements HttpSessi
this.pingIntervalMillis = pingIntervalMillis;
}

@Nullable
@Override
public SessionProtocol protocol() {
return protocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public void run() {
servedFromCache = false;
numAttemptsSoFar = 1;

if (entry.address().equals(address) && entry.ttlMillis() == ttlMillis) {
if (address.equals(entry.address()) && entry.ttlMillis() == ttlMillis) {
scheduleRefresh(ttlMillis);
} else {
// Replace the old entry with the new one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,13 @@ public EventCount count() {
return EventCount.ZERO;
}

@Nullable
@Override
public EventCount onSuccess() {
return null;
}

@Nullable
@Override
public EventCount onFailure() {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ public EventCount count() {
return snapshot.get();
}

@Nullable
@Override
public EventCount onSuccess() {
return onEvent(Event.SUCCESS);
}

@Nullable
@Override
public EventCount onFailure() {
return onEvent(Event.FAILURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import javax.annotation.Nullable;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;

Expand Down Expand Up @@ -81,6 +83,7 @@ public final EndpointSelectionStrategy selectionStrategy() {
return selectionStrategy;
}

@Nullable
@Override
public final Endpoint select(ClientRequestContext ctx) {
return maybeCreateSelector().select(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;

import javax.annotation.Nullable;

import com.google.common.collect.ImmutableList;

import com.linecorp.armeria.client.ClientRequestContext;
Expand Down Expand Up @@ -139,6 +141,7 @@ static EndpointGroup of(EndpointSelectionStrategy selectionStrategy,
* which was specified when constructing this {@link EndpointGroup},
* or {@code null} if this {@link EndpointGroup} is empty.
*/
@Nullable
@Override
Endpoint select(ClientRequestContext ctx);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;

import com.linecorp.armeria.client.ClientRequestContext;
import com.linecorp.armeria.client.Endpoint;
import com.linecorp.armeria.common.util.AbstractListenable;
Expand Down Expand Up @@ -66,6 +68,7 @@ public EndpointSelectionStrategy selectionStrategy() {
return first.selectionStrategy();
}

@Nullable
@Override
public Endpoint select(ClientRequestContext ctx) {
return selector.select(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.Nullable;

import com.linecorp.armeria.client.ClientRequestContext;
import com.linecorp.armeria.client.Endpoint;

Expand Down Expand Up @@ -49,6 +51,7 @@ static class RoundRobinSelector implements EndpointSelector {
this.endpointGroup = requireNonNull(endpointGroup, "endpointGroup");
}

@Nullable
@Override
public Endpoint select(ClientRequestContext ctx) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.concurrent.CompletableFuture;

import javax.annotation.Nullable;

import com.google.common.collect.ImmutableList;

import com.linecorp.armeria.client.ClientRequestContext;
Expand Down Expand Up @@ -57,6 +59,7 @@ public EndpointSelectionStrategy selectionStrategy() {
return selectionStrategy;
}

@Nullable
@Override
public Endpoint select(ClientRequestContext ctx) {
return selector.select(ctx);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import java.util.List;
import java.util.function.ToLongFunction;

import javax.annotation.Nullable;

import com.google.common.hash.Hashing;

import com.linecorp.armeria.client.ClientRequestContext;
Expand Down Expand Up @@ -80,6 +82,7 @@ private static final class StickyEndpointSelector implements EndpointSelector {
this.endpointGroup = requireNonNull(endpointGroup, "endpointGroup");
}

@Nullable
@Override
public Endpoint select(ClientRequestContext ctx) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static final class WeightedRoundRobinSelector implements EndpointSelecto
endpointGroup.addListener(endpoints -> endpointsAndWeights = new EndpointsAndWeights(endpoints));
}

@Nullable
@Override
public Endpoint select(ClientRequestContext ctx) {
final int currentSequence = sequence.getAndIncrement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Supplier;

import javax.annotation.Nullable;

import com.linecorp.armeria.common.util.Unwrappable;

/**
Expand Down Expand Up @@ -149,6 +151,7 @@ static Backoff of(String specification) {
*
* @see Unwrappable
*/
@Nullable
@Override
default <T> T as(Class<T> type) {
return Unwrappable.super.as(type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ public String path() {
return headers.path();
}

@Nullable
@Override
public String scheme() {
return headers.scheme();
}

@Nullable
@Override
public String authority() {
return headers.authority();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ public boolean isValueQuoted() {
return valueQuoted;
}

@Nullable
@Override
public String domain() {
return domain;
}

@Nullable
@Override
public String path() {
return path;
Expand All @@ -112,6 +114,7 @@ public boolean isHttpOnly() {
return httpOnly;
}

@Nullable
@Override
public String sameSite() {
return sameSite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,7 @@ private static final class KnownTypesByString {
.distinct()
.collect(toImmutableMap(MediaType::toString, Function.identity(), (a, b) -> a));

@Nullable
static MediaType get(String input) {
return KNOWN_TYPES_BY_STRING.get(input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,13 @@ protected NonWrappingRequestContext(
this.rpcReq = rpcReq;
}

@Nullable
@Override
public HttpRequest request() {
return req;
}

@Nullable
@Override
public RpcRequest rpcRequest() {
return rpcReq;
Expand Down Expand Up @@ -174,6 +176,7 @@ public final String decodedPath() {
return this.decodedPath = ArmeriaHttpUtil.decodePath(path);
}

@Nullable
@Override
public final String query() {
return query;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public String decodedPath() {
return delegate().decodedPath();
}

@Nullable
@Override
public String query() {
return delegate().query();
Expand Down
Loading

0 comments on commit e029800

Please sign in to comment.