Remove Xlint exclusions from gradle files (part 2)

Backport of #54576.

This commit is part of issue #40366 to remove disabled Xlint warnings
from gradle files. Remove the Xlint exclusions from the following files:

- x-pack/plugin/rollup/build.gradle
- x-pack/plugin/monitoring/build.gradle
- x-pack/qa/rolling-upgrade-basic/build.gradle

Add type parameters to parameterized types. Add wildcard-type parameters
or bounded wildcard-type parameters. Suppress `unchecked` and `rawtypes`
warnings at method level.
This commit is contained in:
Maria Ralli 2020-04-02 17:04:31 +03:00 committed by Rory Hunter
parent 2da2305587
commit aa697346c4
14 changed files with 31 additions and 37 deletions

View File

@ -23,9 +23,6 @@ dependencies {
testCompile project(xpackModule('ilm'))
}
compileJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
configurations {
testArtifacts.extendsFrom testRuntime
}

View File

@ -81,7 +81,7 @@ public class HttpExporter extends Exporter {
private static Setting.AffixSettingDependency TYPE_DEPENDENCY = new Setting.AffixSettingDependency() {
@Override
public Setting.AffixSetting getSetting() {
public Setting.AffixSetting<String> getSetting() {
return Exporter.TYPE_SETTING;
}

View File

@ -209,7 +209,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
assertThat(exportedDoc.getCluster(), equalTo(clusterUUID));
});
final ActionListener listener = (ActionListener) i.getArguments()[1];
final ActionListener<?> listener = (ActionListener) i.getArguments()[1];
listener.onResponse(null);
return Void.TYPE;
}).when(exporters).export(any(Collection.class), any(ActionListener.class));
@ -348,7 +348,7 @@ public class TransportMonitoringBulkActionTests extends ESTestCase {
final Collection<MonitoringDoc> exportedDocs = (Collection) i.getArguments()[0];
assertThat(exportedDocs, is(docs));
final ActionListener listener = (ActionListener) i.getArguments()[1];
final ActionListener<?> listener = (ActionListener) i.getArguments()[1];
listener.onResponse(null);
return Void.TYPE;
}).when(exporters).export(any(Collection.class), any(ActionListener.class));

View File

@ -919,7 +919,7 @@ public class HttpExporterIT extends MonitoringIntegTestCase {
BulkRequest bulkRequest = Requests.bulkRequest()
.add(new BytesArray(requestBody.getBytes(StandardCharsets.UTF_8)), null, null, XContentType.JSON);
assertThat(bulkRequest.numberOfActions(), equalTo(numberOfActions));
for (DocWriteRequest actionRequest : bulkRequest.requests()) {
for (DocWriteRequest<?> actionRequest : bulkRequest.requests()) {
assertThat(actionRequest, instanceOf(IndexRequest.class));
}
}

View File

@ -9,10 +9,6 @@ esplugin {
}
archivesBaseName = 'x-pack-rollup'
compileJava.options.compilerArgs << "-Xlint:-rawtypes"
compileTestJava.options.compilerArgs << "-Xlint:-rawtypes"
dependencies {
compileOnly project(":server")

View File

@ -353,7 +353,7 @@ public class RollupJobIdentifierUtils {
* Ensure that the metrics are supported by one or more job caps. There is no notion of "best"
* caps for metrics, it is either supported or not.
*/
private static void checkVSLeaf(ValuesSourceAggregationBuilder.LeafOnly source, List<RollupJobCaps> jobCaps,
private static void checkVSLeaf(ValuesSourceAggregationBuilder.LeafOnly<?,?> source, List<RollupJobCaps> jobCaps,
Set<RollupJobCaps> bestCaps) {
ArrayList<RollupJobCaps> localCaps = new ArrayList<>();
for (RollupJobCaps cap : jobCaps) {

View File

@ -354,8 +354,8 @@ public class RollupRequestTranslator {
* @param <T> The type of ValueSourceAggBuilder that we are working with
* @return the translated multi-bucket ValueSourceAggBuilder
*/
private static <T extends ValuesSourceAggregationBuilder> List<AggregationBuilder>
translateVSAggBuilder(ValuesSourceAggregationBuilder source, NamedWriteableRegistry registry, Supplier<T> factory) {
private static <T extends ValuesSourceAggregationBuilder<?, ?>> List<AggregationBuilder>
translateVSAggBuilder(T source, NamedWriteableRegistry registry, Supplier<T> factory) {
T rolled = factory.get();
@ -446,7 +446,7 @@ public class RollupRequestTranslator {
* most of the leafs to easily clone them
* @return The translated leaf aggregation
*/
private static List<AggregationBuilder> translateVSLeaf(ValuesSourceAggregationBuilder.LeafOnly metric,
private static List<AggregationBuilder> translateVSLeaf(ValuesSourceAggregationBuilder.LeafOnly<?,?> metric,
NamedWriteableRegistry registry) {
List<AggregationBuilder> rolledMetrics;
@ -480,8 +480,8 @@ public class RollupRequestTranslator {
NamedWriteableAwareStreamInput in =
new NamedWriteableAwareStreamInput(stream, registry)) {
ValuesSourceAggregationBuilder serialized
= ((ValuesSourceAggregationBuilder)in.readNamedWriteable(AggregationBuilder.class))
ValuesSourceAggregationBuilder<?, ?> serialized
= ((ValuesSourceAggregationBuilder<?,?>)in.readNamedWriteable(AggregationBuilder.class))
.field(RollupField.formatFieldName(metric, RollupField.VALUE));
return Collections.singletonList(serialized);

View File

@ -396,7 +396,7 @@ public class RollupResponseTranslator {
* Unrolls Multibucket aggregations (e.g. terms, histograms, etc). This overload signature should be
* called by other internal methods in this class, rather than directly calling the per-type methods.
*/
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
private static InternalAggregation unrollMultiBucket(InternalMultiBucketAggregation rolled, InternalMultiBucketAggregation original,
InternalMultiBucketAggregation currentTree) {
@ -449,7 +449,7 @@ public class RollupResponseTranslator {
* @param source The rolled aggregation that we wish to unroll
* @param bucketFactory A Trifunction which generates new buckets for the given type of multibucket
*/
private static <A extends InternalMultiBucketAggregation,
private static <A extends InternalMultiBucketAggregation<A, B>,
B extends InternalBucket,
T extends InternalMultiBucketAggregation<A, B>>
InternalAggregation unrollMultiBucket(T source, T original, T currentTree,

View File

@ -27,6 +27,7 @@ import org.elasticsearch.search.aggregations.metrics.MinAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder;
import org.elasticsearch.search.aggregations.metrics.ValueCountAggregationBuilder;
import org.elasticsearch.search.aggregations.support.ValueType;
import org.elasticsearch.search.aggregations.support.ValuesSource;
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.xpack.core.indexing.AsyncTwoPhaseIndexer;
@ -287,7 +288,7 @@ public abstract class RollupIndexer extends AsyncTwoPhaseIndexer<Map<String, Obj
if (metrics.isEmpty() == false) {
final String field = metricConfig.getField();
for (String metric : metrics) {
ValuesSourceAggregationBuilder.LeafOnly newBuilder;
ValuesSourceAggregationBuilder.LeafOnly<? extends ValuesSource, ? extends AggregationBuilder> newBuilder;
if (metric.equals(MetricConfig.MIN.getPreferredName())) {
newBuilder = new MinAggregationBuilder(formatFieldName(field, MinAggregationBuilder.NAME, RollupField.VALUE));
} else if (metric.equals(MetricConfig.MAX.getPreferredName())) {
@ -295,7 +296,7 @@ public abstract class RollupIndexer extends AsyncTwoPhaseIndexer<Map<String, Obj
} else if (metric.equals(MetricConfig.AVG.getPreferredName())) {
// Avgs are sum + count
newBuilder = new SumAggregationBuilder(formatFieldName(field, AvgAggregationBuilder.NAME, RollupField.VALUE));
ValuesSourceAggregationBuilder.LeafOnly countBuilder
ValuesSourceAggregationBuilder.LeafOnly<ValuesSource, ValueCountAggregationBuilder> countBuilder
= new ValueCountAggregationBuilder(
formatFieldName(field, AvgAggregationBuilder.NAME, RollupField.COUNT_FIELD), ValueType.NUMERIC);
countBuilder.field(field);

View File

@ -113,7 +113,7 @@ public class RollupRequestTranslationTests extends ESTestCase {
int i = ESTestCase.randomIntBetween(0, 2);
List<AggregationBuilder> translated = new ArrayList<>();
Class clazz = null;
Class<? extends AggregationBuilder> clazz = null;
String fieldName = null;
int numAggs = 1;

View File

@ -52,7 +52,7 @@ import static org.mockito.Mockito.when;
public class PutJobStateMachineTests extends ESTestCase {
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testCreateIndexException() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap());
@ -78,7 +78,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(CreateIndexAction.INSTANCE), any(CreateIndexRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testIndexAlreadyExists() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());
@ -110,7 +110,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testIndexMetadata() throws InterruptedException {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());
@ -153,7 +153,7 @@ public class PutJobStateMachineTests extends ESTestCase {
latch.await(4, TimeUnit.SECONDS);
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetMappingFails() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap());
@ -177,7 +177,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testNoMetadataInMapping() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());
@ -211,7 +211,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testMetadataButNotRollup() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());
@ -249,7 +249,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testNoMappingVersion() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());
@ -286,7 +286,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testJobAlreadyInMapping() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap());
@ -323,7 +323,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(GetMappingsAction.INSTANCE), any(GetMappingsRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testAddJobToMapping() {
final RollupJobConfig unrelatedJob =
ConfigTestHelpers.randomRollupJobConfig(random(), ESTestCase.randomAlphaOfLength(10), "foo", "rollup_index_foo");
@ -372,7 +372,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(client).execute(eq(PutMappingAction.INSTANCE), any(PutMappingRequest.class), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testTaskAlreadyExists() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random(), "foo"), Collections.emptyMap());
@ -395,7 +395,7 @@ public class PutJobStateMachineTests extends ESTestCase {
verify(tasksService).sendStartRequest(eq(job.getConfig().getId()), eq(RollupField.TASK_NAME), eq(job), any());
}
@SuppressWarnings("unchecked")
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testStartTask() {
RollupJob job = new RollupJob(ConfigTestHelpers.randomRollupJobConfig(random()), Collections.emptyMap());

View File

@ -474,11 +474,11 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
}
executeTestCase(dataset, job, System.currentTimeMillis(), (resp) -> {
assertThat(resp.size(), greaterThan(0));
for (DocWriteRequest request : resp) {
for (IndexRequest request : resp) {
assertThat(request.index(), equalTo(rollupIndex));
assertThat(request.type(), equalTo("_doc"));
Map<String, Object> source = ((IndexRequest) request).sourceAsMap();
Map<String, Object> source = request.sourceAsMap();
assertThat(source.get("_rollup.version"), equalTo(newIDScheme ? 2 : 1));
assertThat(source.get("ts.date_histogram.interval"), equalTo(timeInterval.toString()));

View File

@ -79,5 +79,3 @@ for (Version bwcVersion : bwcVersions.wireCompatible) {
dependsOn "${baseName}#upgradedClusterTest"
}
}
compileTestJava.options.compilerArgs << "-Xlint:-cast,-rawtypes,-unchecked"

View File

@ -22,6 +22,7 @@ public class BasicLicenseUpgradeIT extends AbstractUpgradeTestCase {
assertBusy(this::checkNonExpiringBasicLicense);
}
@SuppressWarnings("unchecked")
private void checkBasicLicense() throws Exception {
Response licenseResponse = client().performRequest(new Request("GET", "/_license"));
Map<String, Object> licenseResponseMap = entityAsMap(licenseResponse);
@ -30,6 +31,7 @@ public class BasicLicenseUpgradeIT extends AbstractUpgradeTestCase {
assertEquals("active", licenseMap.get("status"));
}
@SuppressWarnings("unchecked")
private void checkNonExpiringBasicLicense() throws Exception {
Response licenseResponse = client().performRequest(new Request("GET", "/_license"));
Map<String, Object> licenseResponseMap = entityAsMap(licenseResponse);