Skip to content

Commit 3db72c7

Browse files
connorworleygavinbunney
authored andcommitted
Add -Werror and fix all warnings (#1917)
This converts all javac warnings to errors, and fixes all warnings errorprone or otherwise! Since NullAway generates a lot of warnings that will take more effort to fix, I've temporarily disabled it.
1 parent c9c55e1 commit 3db72c7

File tree

71 files changed

+279
-270
lines changed

Some content is hidden

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

71 files changed

+279
-270
lines changed

build.gradle

+11-10
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,21 @@ subprojects {
8282
errorprone "com.google.errorprone:error_prone_core:2.36.0"
8383
}
8484

85+
options.compilerArgs << "-Werror"
86+
8587
options.errorprone {
86-
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.WARN)
88+
check("NullAway", net.ltgt.gradle.errorprone.CheckSeverity.OFF)
8789
option("NullAway:AnnotatedPackages", "com.netflix.zuul")
88-
check("DeduplicateConstants", net.ltgt.gradle.errorprone.CheckSeverity.WARN)
8990
errorproneArgs.addAll(
90-
// Uncomment to automatically apply fixes for a check.
91-
// N.B: disables all other checks while enabled.
92-
// "-XepPatchChecks:UnnecessaryParentheses",
93-
// "-XepPatchLocation:IN_PLACE",
91+
// Uncomment and remove -Werror javac flag to automatically apply fixes for a check.
92+
// N.B: disables all other checks while enabled.
93+
// "-XepPatchChecks:UnnecessaryParentheses",
94+
// "-XepPatchLocation:IN_PLACE",
9495
"-Xep:ClassCanBeStatic:OFF",
95-
"-Xep:FieldCanBeStatic:OFF",
96-
"-Xep:MethodCanBeStatic:OFF",
97-
"-Xep:Var:OFF",
98-
"-Xep:Varifier:OFF",
96+
"-Xep:EmptyBlockTag:OFF",
97+
"-Xep:FutureReturnValueIgnored:OFF",
98+
"-Xep:InlineMeSuggester:OFF",
99+
"-Xep:MissingSummary:OFF",
99100
)
100101
}
101102
}

zuul-core/src/main/java/com/netflix/config/PatternListStringProperty.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public PatternListStringProperty(String name, String defaultValue) {
3838
protected List<Pattern> derive(String value) {
3939
ArrayList<Pattern> ptns = new ArrayList<>();
4040
if (value != null) {
41-
for (String ptnTxt : value.split(",")) {
41+
for (String ptnTxt : value.split(",", -1)) {
4242
try {
4343
ptns.add(Pattern.compile(ptnTxt.trim()));
4444
} catch (Exception e) {

zuul-core/src/main/java/com/netflix/netty/common/ByteBufUtil.java

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030
public class ByteBufUtil {
3131

32+
@SuppressWarnings("EnumOrdinal")
3233
private static final boolean isAdvancedLeakDetection =
3334
ResourceLeakDetector.getLevel().ordinal() >= ResourceLeakDetector.Level.ADVANCED.ordinal();
3435

zuul-core/src/main/java/com/netflix/netty/common/Http1ConnectionCloseHandler.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
4444
.attr(ConnectionCloseChannelAttributes.CLOSE_AFTER_RESPONSE)
4545
.get();
4646

47-
if (msg instanceof HttpResponse) {
48-
HttpResponse response = (HttpResponse) msg;
49-
if (closePromise != null) {
50-
// Add header to tell client that they should close this connection.
51-
response.headers().set(HttpHeaderNames.CONNECTION, "close");
52-
}
47+
if (msg instanceof HttpResponse response && closePromise != null) {
48+
// Add header to tell client that they should close this connection.
49+
response.headers().set(HttpHeaderNames.CONNECTION, "close");
5350
}
5451

5552
super.write(ctx, msg, promise);

zuul-core/src/main/java/com/netflix/netty/common/SwallowSomeHttp2ExceptionsHandler.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ public SwallowSomeHttp2ExceptionsHandler(Registry registry) {
4040
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
4141
incrementExceptionCounter(cause);
4242

43-
if (cause instanceof Http2Exception) {
44-
Http2Exception h2e = (Http2Exception) cause;
43+
if (cause instanceof Http2Exception h2e) {
4544
if (h2e.error() == Http2Error.NO_ERROR
4645
&& h2e.shutdownHint().equals(Http2Exception.ShutdownHint.GRACEFUL_SHUTDOWN)) {
4746
// This is the exception we threw ourselves to make the http2 codec gracefully close the connection. So

zuul-core/src/main/java/com/netflix/netty/common/accesslog/AccessLogChannelHandler.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.netty.handler.codec.http.HttpResponse;
2828
import io.netty.util.AttributeKey;
2929
import java.time.LocalDateTime;
30+
import java.time.ZoneId;
3031
import org.slf4j.Logger;
3132
import org.slf4j.LoggerFactory;
3233

@@ -137,7 +138,7 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
137138
}
138139

139140
private static class RequestState {
140-
final LocalDateTime dateTime = LocalDateTime.now();
141+
final LocalDateTime dateTime = LocalDateTime.now(ZoneId.systemDefault());
141142
HttpRequest request;
142143
HttpResponse response;
143144
long startTimeNs;

zuul-core/src/main/java/com/netflix/netty/common/accesslog/AccessLogPublisher.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.time.LocalDateTime;
2626
import java.time.format.DateTimeFormatter;
2727
import java.util.List;
28+
import java.util.Locale;
2829
import java.util.function.BiFunction;
2930
import org.slf4j.Logger;
3031
import org.slf4j.LoggerFactory;
@@ -67,7 +68,7 @@ public void log(
6768
String dateTimeStr = dateTime != null ? dateTime.format(DATE_TIME_FORMATTER) : "-----T-:-:-";
6869
String remoteIpStr = (remoteIp != null && !remoteIp.isEmpty()) ? remoteIp : "-";
6970
String port = localPort != null ? localPort.toString() : "-";
70-
String method = request != null ? request.method().toString().toUpperCase() : "-";
71+
String method = request != null ? request.method().toString().toUpperCase(Locale.ROOT) : "-";
7172
String uri = request != null ? request.uri() : "-";
7273
if (uri.length() > URI_LENGTH_LIMIT.get()) {
7374
uri = uri.substring(0, URI_LENGTH_LIMIT.get());

zuul-core/src/main/java/com/netflix/netty/common/channel/config/ChannelConfig.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.netflix.netty.common.channel.config;
1818

1919
import java.util.HashMap;
20+
import java.util.Map;
2021

2122
/**
2223
@@ -30,8 +31,8 @@ public ChannelConfig() {
3031
parameters = new HashMap<>();
3132
}
3233

33-
public ChannelConfig(HashMap<ChannelConfigKey, ChannelConfigValue> parameters) {
34-
this.parameters = (HashMap<ChannelConfigKey, ChannelConfigValue>) parameters.clone();
34+
public ChannelConfig(Map<ChannelConfigKey, ChannelConfigValue> parameters) {
35+
this.parameters = new HashMap<ChannelConfigKey, ChannelConfigValue>(parameters);
3536
}
3637

3738
public void add(ChannelConfigValue param) {

zuul-core/src/main/java/com/netflix/netty/common/http2/DynamicHttp2FrameLogger.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.netflix.netty.common.http2;
1818

19+
import com.google.errorprone.annotations.FormatMethod;
20+
import com.google.errorprone.annotations.FormatString;
1921
import com.netflix.config.DynamicStringSetProperty;
2022
import io.netty.buffer.ByteBuf;
2123
import io.netty.buffer.ByteBufUtil;
@@ -248,7 +250,9 @@ private String toString(ByteBuf buf) {
248250
return ByteBufUtil.hexDump(buf, buf.readerIndex(), length) + "...";
249251
}
250252

251-
private void log(Direction direction, String frame, ChannelHandlerContext ctx, String format, Object... args) {
253+
@FormatMethod
254+
private void log(
255+
Direction direction, String frame, ChannelHandlerContext ctx, @FormatString String format, Object... args) {
252256
if (shouldLogFrame(frame)) {
253257
StringBuilder b = new StringBuilder(200)
254258
.append(direction.name())

zuul-core/src/main/java/com/netflix/netty/common/metrics/EventLoopGroupMetrics.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public EventLoopMetrics getForCurrentEventLoop() {
6666
private static String nameForCurrentEventLoop() {
6767
// We're relying on the knowledge that we name the eventloop threads consistently.
6868
String threadName = Thread.currentThread().getName();
69-
String parts[] = threadName.split("-ClientToZuulWorker-");
69+
String parts[] = threadName.split("-ClientToZuulWorker-", -1);
7070
if (parts.length == 2) {
7171
return parts[1];
7272
}

zuul-core/src/main/java/com/netflix/netty/common/proxyprotocol/HAProxyMessageChannelHandler.java

+54-58
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@ public final class HAProxyMessageChannelHandler extends ChannelInboundHandlerAda
6060

6161
@Override
6262
public void channelRead(ChannelHandlerContext ctx, Object msg) {
63-
if (msg instanceof HAProxyMessage) {
64-
HAProxyMessage hapm = (HAProxyMessage) msg;
63+
if (msg instanceof HAProxyMessage hapm) {
6564
Channel channel = ctx.channel();
6665
channel.attr(ATTR_HAPROXY_MESSAGE).set(hapm);
6766
ctx.channel().closeFuture().addListener((ChannelFutureListener) future -> hapm.release());
@@ -85,32 +84,30 @@ private void parseSrcAddr(HAProxyMessage hapm, Channel channel) {
8584
channel.attr(SourceAddressChannelHandler.ATTR_SOURCE_ADDRESS).set(sourceAddress);
8685

8786
SocketAddress srcAddr;
88-
out:
89-
{
90-
switch (hapm.proxiedProtocol()) {
91-
case UNKNOWN:
92-
throw new IllegalArgumentException("unknown proxy protocol" + sourceAddress);
93-
case TCP4:
94-
case TCP6:
95-
InetSocketAddress inetAddr;
96-
srcAddr = inetAddr =
97-
new InetSocketAddress(InetAddresses.forString(sourceAddress), hapm.sourcePort());
98-
Attrs attrs = channel.attr(Server.CONN_DIMENSIONS).get();
99-
if (inetAddr.getAddress() instanceof Inet4Address) {
100-
HAPM_SRC_IP_VERSION.put(attrs, "v4");
101-
} else if (inetAddr.getAddress() instanceof Inet6Address) {
102-
HAPM_SRC_IP_VERSION.put(attrs, "v6");
103-
} else {
104-
HAPM_SRC_IP_VERSION.put(attrs, "unknown");
105-
}
106-
break out;
107-
case UNIX_STREAM: // TODO: implement
108-
case UDP4:
109-
case UDP6:
110-
case UNIX_DGRAM:
111-
throw new IllegalArgumentException("unknown proxy protocol" + sourceAddress);
112-
}
113-
throw new AssertionError(hapm.proxiedProtocol());
87+
switch (hapm.proxiedProtocol()) {
88+
case UNKNOWN:
89+
throw new IllegalArgumentException("unknown proxy protocol" + sourceAddress);
90+
case TCP4:
91+
case TCP6:
92+
InetSocketAddress inetAddr;
93+
srcAddr =
94+
inetAddr = new InetSocketAddress(InetAddresses.forString(sourceAddress), hapm.sourcePort());
95+
Attrs attrs = channel.attr(Server.CONN_DIMENSIONS).get();
96+
if (inetAddr.getAddress() instanceof Inet4Address) {
97+
HAPM_SRC_IP_VERSION.put(attrs, "v4");
98+
} else if (inetAddr.getAddress() instanceof Inet6Address) {
99+
HAPM_SRC_IP_VERSION.put(attrs, "v6");
100+
} else {
101+
HAPM_SRC_IP_VERSION.put(attrs, "unknown");
102+
}
103+
break;
104+
case UNIX_STREAM: // TODO: implement
105+
case UDP4:
106+
case UDP6:
107+
case UNIX_DGRAM:
108+
throw new IllegalArgumentException("unknown proxy protocol" + sourceAddress);
109+
default:
110+
throw new AssertionError(hapm.proxiedProtocol());
114111
}
115112
channel.attr(SourceAddressChannelHandler.ATTR_REMOTE_ADDR).set(srcAddr);
116113
}
@@ -120,37 +117,36 @@ private void parseDstAddr(HAProxyMessage hapm, Channel channel) {
120117
String destinationAddress = hapm.destinationAddress();
121118
if (destinationAddress != null) {
122119
channel.attr(SourceAddressChannelHandler.ATTR_LOCAL_ADDRESS).set(destinationAddress);
120+
123121
SocketAddress dstAddr;
124-
out:
125-
{
126-
switch (hapm.proxiedProtocol()) {
127-
case UNKNOWN:
128-
throw new IllegalArgumentException("unknown proxy protocol" + destinationAddress);
129-
case TCP4:
130-
case TCP6:
131-
InetSocketAddress inetAddr = new InetSocketAddress(
132-
InetAddresses.forString(destinationAddress), hapm.destinationPort());
133-
dstAddr = inetAddr;
134-
// set ppv2 attr explicitly because ATTR_LOCAL_ADDR could be non ppv2
135-
channel.attr(SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS)
136-
.set(inetAddr);
137-
Attrs attrs = channel.attr(Server.CONN_DIMENSIONS).get();
138-
if (inetAddr.getAddress() instanceof Inet4Address) {
139-
HAPM_DEST_IP_VERSION.put(attrs, "v4");
140-
} else if (inetAddr.getAddress() instanceof Inet6Address) {
141-
HAPM_DEST_IP_VERSION.put(attrs, "v6");
142-
} else {
143-
HAPM_DEST_IP_VERSION.put(attrs, "unknown");
144-
}
145-
HAPM_DEST_PORT.put(attrs, hapm.destinationPort());
146-
break out;
147-
case UNIX_STREAM: // TODO: implement
148-
case UDP4:
149-
case UDP6:
150-
case UNIX_DGRAM:
151-
throw new IllegalArgumentException("unknown proxy protocol" + destinationAddress);
152-
}
153-
throw new AssertionError(hapm.proxiedProtocol());
122+
switch (hapm.proxiedProtocol()) {
123+
case UNKNOWN:
124+
throw new IllegalArgumentException("unknown proxy protocol" + destinationAddress);
125+
case TCP4:
126+
case TCP6:
127+
InetSocketAddress inetAddr =
128+
new InetSocketAddress(InetAddresses.forString(destinationAddress), hapm.destinationPort());
129+
dstAddr = inetAddr;
130+
// set ppv2 attr explicitly because ATTR_LOCAL_ADDR could be non ppv2
131+
channel.attr(SourceAddressChannelHandler.ATTR_PROXY_PROTOCOL_DESTINATION_ADDRESS)
132+
.set(inetAddr);
133+
Attrs attrs = channel.attr(Server.CONN_DIMENSIONS).get();
134+
if (inetAddr.getAddress() instanceof Inet4Address) {
135+
HAPM_DEST_IP_VERSION.put(attrs, "v4");
136+
} else if (inetAddr.getAddress() instanceof Inet6Address) {
137+
HAPM_DEST_IP_VERSION.put(attrs, "v6");
138+
} else {
139+
HAPM_DEST_IP_VERSION.put(attrs, "unknown");
140+
}
141+
HAPM_DEST_PORT.put(attrs, hapm.destinationPort());
142+
break;
143+
case UNIX_STREAM: // TODO: implement
144+
case UDP4:
145+
case UDP6:
146+
case UNIX_DGRAM:
147+
throw new IllegalArgumentException("unknown proxy protocol" + destinationAddress);
148+
default:
149+
throw new AssertionError(hapm.proxiedProtocol());
154150
}
155151
channel.attr(SourceAddressChannelHandler.ATTR_LOCAL_ADDR).set(dstAddr);
156152
}

zuul-core/src/main/java/com/netflix/netty/common/proxyprotocol/StripUntrustedProxyHeadersHandler.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ public StripUntrustedProxyHeadersHandler(AllowWhen allowWhen) {
6262

6363
@Override
6464
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
65-
if (msg instanceof HttpRequest) {
66-
HttpRequest req = (HttpRequest) msg;
67-
65+
if (msg instanceof HttpRequest req) {
6866
switch (allowWhen) {
6967
case NEVER:
7068
stripXFFHeaders(req);

zuul-core/src/main/java/com/netflix/zuul/Attrs.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.Collections;
2121
import java.util.IdentityHashMap;
2222
import java.util.LinkedHashSet;
23-
import java.util.Map;
2423
import java.util.Objects;
2524
import java.util.Set;
2625
import java.util.function.BiConsumer;
@@ -36,7 +35,7 @@
3635
*/
3736
public final class Attrs {
3837

39-
final Map<Key<?>, Object> storage = new IdentityHashMap<>();
38+
final IdentityHashMap<Key<?>, Object> storage = new IdentityHashMap<>();
4039

4140
public static <T> Key<T> newKey(String keyName) {
4241
return new Key<>(keyName);

zuul-core/src/main/java/com/netflix/zuul/DefaultFilterFactory.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.netflix.zuul;
1717

1818
import com.netflix.zuul.filters.ZuulFilter;
19+
import java.lang.reflect.InvocationTargetException;
1920

2021
/**
2122
* Default factory for creating instances of ZuulFilter.
@@ -30,7 +31,9 @@ public class DefaultFilterFactory implements FilterFactory {
3031
* @return A new instance of ZuulFilter
3132
*/
3233
@Override
33-
public ZuulFilter<?, ?> newInstance(Class<?> clazz) throws InstantiationException, IllegalAccessException {
34-
return (ZuulFilter<?, ?>) clazz.newInstance();
34+
public ZuulFilter<?, ?> newInstance(Class<?> clazz)
35+
throws InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
36+
NoSuchMethodException {
37+
return (ZuulFilter<?, ?>) clazz.getDeclaredConstructor().newInstance();
3538
}
3639
}

zuul-core/src/main/java/com/netflix/zuul/context/Debug.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.ArrayList;
2424
import java.util.Iterator;
2525
import java.util.List;
26+
import java.util.Locale;
2627
import rx.Observable;
2728

2829
/**
@@ -157,7 +158,7 @@ public static Observable<Boolean> writeDebugRequest(
157158
"%s:: %s LINE: %s %s %s",
158159
prefix,
159160
arrow,
160-
request.getMethod().toUpperCase(),
161+
request.getMethod().toUpperCase(Locale.ROOT),
161162
request.getPathAndQuery(),
162163
request.getProtocol()));
163164
obs = Debug.writeDebugMessage(context, request, prefix, arrow);

zuul-core/src/main/java/com/netflix/zuul/context/SessionContext.java

+1
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public T defaultValue() {
112112
}
113113
}
114114

115+
@SuppressWarnings("UnnecessaryStringBuilder")
115116
public SessionContext() {
116117
// Use a higher than default initial capacity for the hashmap as we generally have more than the default
117118
// 16 entries.

zuul-core/src/main/java/com/netflix/zuul/filters/FilterType.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.netflix.zuul.filters;
1818

19+
import java.util.Locale;
20+
1921
/**
2022
* User: Mike Smith
2123
* Date: 11/13/15
@@ -38,7 +40,7 @@ public String toString() {
3840
}
3941

4042
public static FilterType parse(String str) {
41-
str = str.toLowerCase();
43+
str = str.toLowerCase(Locale.ROOT);
4244
switch (str) {
4345
case "in":
4446
return INBOUND;

zuul-core/src/main/java/com/netflix/zuul/filters/common/GZipResponseFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import io.netty.handler.codec.http.DefaultLastHttpContent;
3636
import io.netty.handler.codec.http.HttpContent;
3737
import io.netty.handler.codec.http.LastHttpContent;
38+
import java.util.Locale;
3839

3940
/**
4041
* General-purpose filter for gzipping/ungzipping response bodies if requested/needed. This should be run as late as
@@ -121,7 +122,7 @@ private boolean isGzippableContentType(HttpResponseMessage response) {
121122
if (charsetIndex > 0) {
122123
ct = ct.substring(0, charsetIndex);
123124
}
124-
return GZIPPABLE_CONTENT_TYPES.get().contains(ct.toLowerCase());
125+
return GZIPPABLE_CONTENT_TYPES.get().contains(ct.toLowerCase(Locale.ROOT));
125126
}
126127
return false;
127128
}

0 commit comments

Comments
 (0)