Skip to content

Commit f4c53c1

Browse files
authored
Merge branch 'main' into feature/create-disk-memory-health-checker
2 parents 8ce5606 + c7b2a44 commit f4c53c1

207 files changed

Lines changed: 2424 additions & 662 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/jmh/src/jmh/java/com/linecorp/armeria/server/RoutersBenchmark.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private static ServiceConfig newServiceConfig(Route route) {
7878
final Path multipartUploadsLocation = Flags.defaultMultipartUploadsLocation();
7979
final ServiceErrorHandler serviceErrorHandler = ServerErrorHandler.ofDefault().asServiceErrorHandler();
8080
return new ServiceConfig(route, route,
81-
SERVICE, defaultLogName, defaultServiceName, defaultServiceNaming, 0, 0,
81+
SERVICE, defaultServiceName, defaultServiceNaming, defaultLogName, 0, 0,
8282
false, AccessLogWriter.disabled(), CommonPools.blockingTaskExecutor(),
8383
SuccessFunction.always(), 0, multipartUploadsLocation,
8484
MultipartRemovalStrategy.ON_RESPONSE_COMPLETION,

build.gradle

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ plugins {
2323
alias libs.plugins.kotlin apply false
2424
alias libs.plugins.ktlint apply false
2525
alias libs.plugins.errorprone apply false
26+
alias libs.plugins.nullaway apply false
2627
}
2728

2829
allprojects {
@@ -171,13 +172,34 @@ configure(projectsWithFlags('java')) {
171172
// Error Prone compiler
172173
if (!rootProject.hasProperty('noLint')) {
173174
apply plugin: 'net.ltgt.errorprone'
175+
apply plugin: 'net.ltgt.nullaway'
174176

175177
dependencies {
176178
errorprone libs.errorprone.core
179+
errorprone libs.nullaway
180+
}
181+
182+
nullaway {
183+
annotatedPackages.add("com.linecorp.armeria")
177184
}
178185

179186
tasks.withType(JavaCompile) {
180187
options.errorprone.excludedPaths = '.*/gen-src/.*'
188+
options.errorprone.nullaway {
189+
if (name.toLowerCase().contains("test")) {
190+
// Disable NullAway for tests for now.
191+
disable()
192+
} else if (name.matches(/compileJava[0-9]+.*/)) {
193+
// Disable MR-JAR classes which seem to confuse NullAway and break the build.
194+
disable()
195+
} else if (project != project(':core')) {
196+
// TODO(trustin): Enable NullAway for all projects once we fix all violations.
197+
warn()
198+
} else {
199+
error()
200+
assertsEnabled = true
201+
}
202+
}
181203
}
182204
}
183205

core/src/main/java/com/linecorp/armeria/client/AbstractHttpRequestHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import io.netty.channel.ChannelPromise;
5555
import io.netty.handler.codec.http.HttpHeaderValues;
5656
import io.netty.handler.codec.http2.Http2Error;
57-
import io.netty.handler.proxy.ProxyConnectException;
5857

5958
abstract class AbstractHttpRequestHandler implements ChannelFutureListener {
6059

@@ -216,6 +215,7 @@ RequestHeaders mergedRequestHeaders(RequestHeaders headers) {
216215
* {@link Channel#flush()} when each write unit is done.
217216
*/
218217
final void writeHeaders(RequestHeaders headers, boolean needs100Continue) {
218+
assert session != null;
219219
final SessionProtocol protocol = session.protocol();
220220
assert protocol != null;
221221
if (needs100Continue) {
@@ -377,8 +377,7 @@ final void failAndReset(Throwable cause) {
377377
session.markUnacquirable();
378378
}
379379

380-
if (cause instanceof ProxyConnectException || cause instanceof ResponseCompleteException) {
381-
// - ProxyConnectException is handled by HttpSessionHandler.exceptionCaught().
380+
if (cause instanceof ResponseCompleteException) {
382381
// - ResponseCompleteException means the response is successfully received.
383382
state = State.DONE;
384383
cancel();

core/src/main/java/com/linecorp/armeria/client/Client.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.linecorp.armeria.common.Response;
2525
import com.linecorp.armeria.common.RpcRequest;
2626
import com.linecorp.armeria.common.RpcResponse;
27+
import com.linecorp.armeria.common.annotation.Nullable;
2728
import com.linecorp.armeria.common.util.Unwrappable;
2829

2930
/**
@@ -71,6 +72,7 @@ public interface Client<I extends Request, O extends Response> extends Unwrappab
7172
* @see ClientFactory#unwrap(Object, Class)
7273
* @see Unwrappable
7374
*/
75+
@Nullable
7476
@Override
7577
default <T> T as(Class<T> type) {
7678
requireNonNull(type, "type");

core/src/main/java/com/linecorp/armeria/client/ClientRequestContextWrapper.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,31 @@ public ClientRequestContext newDerivedContext(RequestId id, @Nullable HttpReques
5252
return unwrap().newDerivedContext(id, req, rpcReq, endpoint);
5353
}
5454

55+
@Nullable
5556
@Override
5657
public EndpointGroup endpointGroup() {
5758
return unwrap().endpointGroup();
5859
}
5960

61+
@Nullable
6062
@Override
6163
public Endpoint endpoint() {
6264
return unwrap().endpoint();
6365
}
6466

67+
@Nullable
6568
@Override
6669
public String fragment() {
6770
return unwrap().fragment();
6871
}
6972

73+
@Nullable
7074
@Override
7175
public String authority() {
7276
return unwrap().authority();
7377
}
7478

79+
@Nullable
7580
@Override
7681
public String host() {
7782
return unwrap().host();

core/src/main/java/com/linecorp/armeria/client/DecoratingClientFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,13 @@ public Object newClient(ClientBuilderParams params) {
108108
return unwrap().newClient(params);
109109
}
110110

111+
@Nullable
111112
@Override
112113
public <T> ClientBuilderParams clientBuilderParams(T client) {
113114
return unwrap().clientBuilderParams(client);
114115
}
115116

117+
@Nullable
116118
@Override
117119
public <T> T unwrap(Object client, Class<T> type) {
118120
return unwrap().unwrap(client, type);

core/src/main/java/com/linecorp/armeria/client/DefaultClientFactory.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ public Object newClient(ClientBuilderParams params) {
184184
"No ClientFactory for scheme: " + scheme + " matched clientType: " + clientType);
185185
}
186186

187+
@Nullable
187188
@Override
188189
public <T> T unwrap(Object client, Class<T> type) {
189190
final T params = ClientFactory.super.unwrap(client, type);

core/src/main/java/com/linecorp/armeria/client/DefaultDnsCache.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public void cache(DnsQuestion question, UnknownHostException cause) {
147147
}
148148
}
149149

150+
@Nullable
150151
@Override
151152
public List<DnsRecord> get(DnsQuestion question) throws UnknownHostException {
152153
requireNonNull(question, "question");

core/src/main/java/com/linecorp/armeria/client/DefaultRequestOptions.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public long maxResponseLength() {
6868
return maxResponseLength;
6969
}
7070

71+
@Nullable
7172
@Override
7273
public Long requestAutoAbortDelayMillis() {
7374
return requestAutoAbortDelayMillis;
@@ -78,6 +79,7 @@ public Map<AttributeKey<?>, Object> attrs() {
7879
return attributeMap;
7980
}
8081

82+
@Nullable
8183
@Override
8284
public ExchangeType exchangeType() {
8385
return exchangeType;

core/src/main/java/com/linecorp/armeria/client/Endpoint.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import java.util.concurrent.ScheduledExecutorService;
3838
import java.util.function.Consumer;
3939

40+
import javax.annotation.Nonnull;
41+
4042
import com.github.benmanes.caffeine.cache.Cache;
4143
import com.github.benmanes.caffeine.cache.Caffeine;
4244
import com.google.common.annotations.VisibleForTesting;
@@ -323,6 +325,7 @@ public EndpointSelectionStrategy selectionStrategy() {
323325
return EndpointSelectionStrategy.weightedRoundRobin();
324326
}
325327

328+
@Nonnull
326329
@Override
327330
public Endpoint selectNow(ClientRequestContext ctx) {
328331
return this;
@@ -693,16 +696,40 @@ public <T> Endpoint withAttr(AttributeKey<T> key, @Nullable T value) {
693696
if (value == null) {
694697
return this;
695698
}
696-
return withAttrs(Attributes.of(key, value));
699+
return replaceAttrs(Attributes.of(key, value));
697700
}
698701

699702
if (attributes.attr(key) == value) {
700703
return this;
701704
} else {
702705
final AttributesBuilder attributesBuilder = attributes.toBuilder();
703706
attributesBuilder.set(key, value);
704-
return withAttrs(attributesBuilder.build());
707+
return replaceAttrs(attributesBuilder.build());
708+
}
709+
}
710+
711+
/**
712+
* Returns a new {@link Endpoint} with the specified {@link Attributes}.
713+
* Note that the {@link #attrs()} of this {@link Endpoint} is merged with the specified
714+
* {@link Attributes}. For attributes with the same {@link AttributeKey}, the attribute
715+
* in {@param newAttributes} has higher precedence.
716+
*/
717+
@UnstableApi
718+
@SuppressWarnings("unchecked")
719+
public Endpoint withAttrs(Attributes newAttributes) {
720+
requireNonNull(newAttributes, "newAttributes");
721+
if (newAttributes.isEmpty()) {
722+
return this;
705723
}
724+
if (attrs().isEmpty()) {
725+
return replaceAttrs(newAttributes);
726+
}
727+
final AttributesBuilder builder = attrs().toBuilder();
728+
newAttributes.attrs().forEachRemaining(entry -> {
729+
final AttributeKey<Object> key = (AttributeKey<Object>) entry.getKey();
730+
builder.set(key, entry.getValue());
731+
});
732+
return new Endpoint(type, host, ipAddr, port, weight, builder.build());
706733
}
707734

708735
/**
@@ -711,7 +738,7 @@ public <T> Endpoint withAttr(AttributeKey<T> key, @Nullable T value) {
711738
* {@link Attributes}.
712739
*/
713740
@UnstableApi
714-
public Endpoint withAttrs(Attributes newAttributes) {
741+
public Endpoint replaceAttrs(Attributes newAttributes) {
715742
requireNonNull(newAttributes, "newAttributes");
716743
if (attrs().isEmpty() && newAttributes.isEmpty()) {
717744
return this;

0 commit comments

Comments
 (0)