Skip to content

Commit 3473987

Browse files
authored
Remove Xlint exclusions from gradle files (#52542)
This commit is part of issue #40366 to remove disabled Xlint warnings from gradle files. In particular, it removes the Xlint exclusions from the following files: - benchmarks/build.gradle - client/client-benchmark-noop-api-plugin/build.gradle - x-pack/qa/rolling-upgrade/build.gradle - x-pack/qa/third-party/active-directory/build.gradle - modules/transport-netty4/build.gradle For the first three files no code adjustments were needed. For x-pack/qa/third-party/active-directory move the suppression at the code level. For transport-netty4 replace the variable arguments with ArrayLists and remove any redundant casts.
1 parent f5ca487 commit 3473987

File tree

9 files changed

+22
-33
lines changed

9 files changed

+22
-33
lines changed

benchmarks/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ dependencies {
4141
runtime 'org.apache.commons:commons-math3:3.2'
4242
}
4343

44-
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked,-processing"
4544
// enable the JMH's BenchmarkProcessor to generate the final benchmark classes
4645
// needs to be added separately otherwise Gradle will quote it and javac will fail
4746
compileJava.options.compilerArgs.addAll(["-processor", "org.openjdk.jmh.generators.BenchmarkProcessor"])

client/client-benchmark-noop-api-plugin/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ assemble.enabled = false
3333
dependencyLicenses.enabled = false
3434
dependenciesInfo.enabled = false
3535

36-
compileJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
37-
3836
// no unit tests
3937
test.enabled = false
4038
integTest.enabled = false

modules/transport-netty4/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ esplugin {
3232
classname 'org.elasticsearch.transport.Netty4Plugin'
3333
}
3434

35-
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
36-
3735
dependencies {
3836
// network stack
3937
compile "io.netty:netty-buffer:${versions.netty}"

modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpClient.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ public Collection<FullHttpResponse> get(SocketAddress remoteAddress, String... u
102102
return sendRequests(remoteAddress, requests);
103103
}
104104

105-
@SafeVarargs // Safe not because it doesn't do anything with the type parameters but because it won't leak them into other methods.
106-
public final Collection<FullHttpResponse> post(SocketAddress remoteAddress, Tuple<String, CharSequence>... urisAndBodies)
105+
public final Collection<FullHttpResponse> post(SocketAddress remoteAddress, List<Tuple<String, CharSequence>> urisAndBodies)
107106
throws InterruptedException {
108107
return processRequestsWithBody(HttpMethod.POST, remoteAddress, urisAndBodies);
109108
}
@@ -114,15 +113,14 @@ public final FullHttpResponse post(SocketAddress remoteAddress, FullHttpRequest
114113
return responses.iterator().next();
115114
}
116115

117-
@SafeVarargs // Safe not because it doesn't do anything with the type parameters but because it won't leak them into other methods.
118-
public final Collection<FullHttpResponse> put(SocketAddress remoteAddress, Tuple<String, CharSequence>... urisAndBodies)
116+
public final Collection<FullHttpResponse> put(SocketAddress remoteAddress, List<Tuple<String, CharSequence>> urisAndBodies)
119117
throws InterruptedException {
120118
return processRequestsWithBody(HttpMethod.PUT, remoteAddress, urisAndBodies);
121119
}
122120

123-
private Collection<FullHttpResponse> processRequestsWithBody(HttpMethod method, SocketAddress remoteAddress, Tuple<String,
124-
CharSequence>... urisAndBodies) throws InterruptedException {
125-
Collection<HttpRequest> requests = new ArrayList<>(urisAndBodies.length);
121+
private Collection<FullHttpResponse> processRequestsWithBody(HttpMethod method, SocketAddress remoteAddress, List<Tuple<String,
122+
CharSequence>> urisAndBodies) throws InterruptedException {
123+
Collection<HttpRequest> requests = new ArrayList<>(urisAndBodies.size());
126124
for (Tuple<String, CharSequence> uriAndBody : urisAndBodies) {
127125
ByteBuf content = Unpooled.copiedBuffer(uriAndBody.v2(), StandardCharsets.UTF_8);
128126
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, method, uriAndBody.v1(), content);

modules/transport-netty4/src/test/java/org/elasticsearch/http/netty4/Netty4HttpRequestSizeLimitIT.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
import org.elasticsearch.test.ESIntegTestCase.Scope;
3434
import io.netty.handler.codec.http.HttpResponseStatus;
3535

36+
import java.util.ArrayList;
3637
import java.util.Collection;
38+
import java.util.List;
3739

3840
import static org.hamcrest.Matchers.equalTo;
3941
import static org.hamcrest.Matchers.greaterThan;
@@ -77,25 +79,23 @@ public void testLimitsInFlightRequests() throws Exception {
7779
bulkRequest.append(System.lineSeparator());
7880
}
7981

80-
@SuppressWarnings("unchecked")
81-
Tuple<String, CharSequence>[] requests = new Tuple[150];
82-
for (int i = 0; i < requests.length; i++) {
83-
requests[i] = Tuple.tuple("/index/_bulk", bulkRequest);
82+
List<Tuple<String, CharSequence>> requests = new ArrayList<>();
83+
for (int i = 0; i < 150; i++) {
84+
requests.add(Tuple.tuple("/index/_bulk", bulkRequest));
8485
}
8586

8687
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
87-
TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress
88-
().boundAddresses());
88+
TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses());
8989

9090
try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
91-
Collection<FullHttpResponse> singleResponse = nettyHttpClient.post(transportAddress.address(), requests[0]);
91+
Collection<FullHttpResponse> singleResponse = nettyHttpClient.post(transportAddress.address(), requests.subList(0, 1));
9292
try {
9393
assertThat(singleResponse, hasSize(1));
9494
assertAtLeastOnceExpectedStatus(singleResponse, HttpResponseStatus.OK);
9595

9696
Collection<FullHttpResponse> multipleResponses = nettyHttpClient.post(transportAddress.address(), requests);
9797
try {
98-
assertThat(multipleResponses, hasSize(requests.length));
98+
assertThat(multipleResponses, hasSize(requests.size()));
9999
assertAtLeastOnceExpectedStatus(multipleResponses, HttpResponseStatus.TOO_MANY_REQUESTS);
100100
} finally {
101101
multipleResponses.forEach(ReferenceCounted::release);
@@ -109,21 +109,19 @@ public void testLimitsInFlightRequests() throws Exception {
109109
public void testDoesNotLimitExcludedRequests() throws Exception {
110110
ensureGreen();
111111

112-
@SuppressWarnings("unchecked")
113-
Tuple<String, CharSequence>[] requestUris = new Tuple[1500];
114-
for (int i = 0; i < requestUris.length; i++) {
115-
requestUris[i] = Tuple.tuple("/_cluster/settings",
116-
"{ \"transient\": {\"search.default_search_timeout\": \"40s\" } }");
112+
List<Tuple<String, CharSequence>> requestUris = new ArrayList<>();
113+
for (int i = 0; i < 1500; i++) {
114+
requestUris.add(Tuple.tuple("/_cluster/settings",
115+
"{ \"transient\": {\"search.default_search_timeout\": \"40s\" } }"));
117116
}
118117

119118
HttpServerTransport httpServerTransport = internalCluster().getInstance(HttpServerTransport.class);
120-
TransportAddress transportAddress = (TransportAddress) randomFrom(httpServerTransport.boundAddress
121-
().boundAddresses());
119+
TransportAddress transportAddress = randomFrom(httpServerTransport.boundAddress().boundAddresses());
122120

123121
try (Netty4HttpClient nettyHttpClient = new Netty4HttpClient()) {
124122
Collection<FullHttpResponse> responses = nettyHttpClient.put(transportAddress.address(), requestUris);
125123
try {
126-
assertThat(responses, hasSize(requestUris.length));
124+
assertThat(responses, hasSize(requestUris.size()));
127125
assertAllInExpectedStatus(responses, HttpResponseStatus.OK);
128126
} finally {
129127
responses.forEach(ReferenceCounted::release);

modules/transport-netty4/src/test/java/org/elasticsearch/transport/netty4/Netty4TransportPublishAddressIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public void testDifferentPorts() throws Exception {
7676
assertThat(boundTransportAddress.boundAddresses().length, greaterThan(1));
7777
for (TransportAddress boundAddress : boundTransportAddress.boundAddresses()) {
7878
assertThat(boundAddress, instanceOf(TransportAddress.class));
79-
TransportAddress inetBoundAddress = (TransportAddress) boundAddress;
79+
TransportAddress inetBoundAddress = boundAddress;
8080
if (inetBoundAddress.address().getAddress() instanceof Inet4Address) {
8181
// IPv4 address is preferred publish address for _local_
8282
assertThat(inetBoundAddress.getPort(), equalTo(boundTransportAddress.publishAddress().getPort()));

x-pack/qa/rolling-upgrade/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ dependencies {
1010
testCompile project(':client:rest-high-level')
1111
}
1212

13-
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"
14-
1513
forbiddenPatterns {
1614
exclude '**/system_key'
1715
}

x-pack/qa/rolling-upgrade/src/test/java/org/elasticsearch/upgrades/TokenBackwardsCompatibilityIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ private void assertRefreshTokenInvalidated(String refreshToken) throws IOExcepti
299299
}
300300
}
301301

302+
@SuppressWarnings("unchecked")
302303
private Map<Version, RestClient> getRestClientByVersion() throws IOException {
303304
Response response = client().performRequest(new Request("GET", "_nodes"));
304305
assertOK(response);
@@ -342,6 +343,7 @@ private void storeTokens(RestClient client, int idx, String accessToken, String
342343
assertOK(indexResponse1);
343344
}
344345

346+
@SuppressWarnings("unchecked")
345347
private Map<String, Object> retrieveStoredTokens(RestClient client, int tokenIdx) throws IOException {
346348
Request getRequest = new Request("GET", "token_backwards_compatibility_it/_doc/old_cluster_token" + tokenIdx);
347349
Response getResponse = client().performRequest(getRequest);

x-pack/qa/third-party/active-directory/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ processTestResources {
1313
from(project(xpackModule('security')).sourceSets.test.resources.srcDirs)
1414
}
1515

16-
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
17-
1816
// we have to repeat these patterns because the security test resources are effectively in the src of this p
1917
forbiddenPatterns {
2018
exclude '**/*.key'

0 commit comments

Comments
 (0)