Skip to content

Commit

Permalink
Enable compiler warnings in xpack core plugin project (#66899)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
2 people authored and pugnascotia committed Mar 22, 2021
1 parent dc7ac98 commit 37a24d5
Show file tree
Hide file tree
Showing 54 changed files with 124 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ public static <E> ArrayList<E> iterableAsArrayList(Iterable<? extends E> element
}
}

@SafeVarargs
@SuppressWarnings("varargs")
public static <E> ArrayList<E> arrayAsArrayList(E... elements) {
if (elements == null) {
throw new NullPointerException("elements");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,15 @@ public static int randomInt(int max) {
}

/** Pick a random object from the given array. The array must not be empty. */
@SafeVarargs
@SuppressWarnings("varargs")
public static <T> T randomFrom(T... array) {
return randomFrom(random(), array);
}

/** Pick a random object from the given array. The array must not be empty. */
@SafeVarargs
@SuppressWarnings("varargs")
public static <T> T randomFrom(Random random, T... array) {
return RandomPicks.randomFrom(random, array);
}
Expand Down
3 changes: 0 additions & 3 deletions x-pack/plugin/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ tasks.named('forbiddenApisMain').configure {
signaturesFiles += files('forbidden/hasher-signatures.txt')
}

tasks.withType(JavaCompile).configureEach {
options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
}

// make LicenseSigner available for testing signed licenses
sourceSets.test.resources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ public void testPITTiebreak() throws Exception {
}
}

@SuppressWarnings({"rawtypes","unchecked"})
private void assertPagination(PointInTimeBuilder pit, int expectedNumDocs, int size, SortBuilder<?>... sorts) throws Exception {
Set<String> seen = new HashSet<>();
SearchRequestBuilder builder = client().prepareSearch()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public boolean equals(Object obj) {
if (obj instanceof AbstractGetResourcesResponse == false) {
return false;
}
AbstractGetResourcesResponse other = (AbstractGetResourcesResponse) obj;
AbstractGetResourcesResponse<?> other = (AbstractGetResourcesResponse<?>) obj;
return Objects.equals(resources, other.resources);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public static class Request extends ActionRequest implements ToXContentObject {
private static final ParseField QUERY = new ParseField("query");
private static final ParseField EVALUATION = new ParseField("evaluation");

@SuppressWarnings({ "unchecked"})
private static final ConstructingObjectParser<Request, Void> PARSER = new ConstructingObjectParser<>(
NAME,
a -> new Request((List<String>) a[0], (QueryProvider) a[1], (Evaluation) a[2]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static class Response extends ActionResponse implements ToXContentObject
public static final ParseField FIELD_SELECTION = new ParseField("field_selection");
public static final ParseField MEMORY_ESTIMATION = new ParseField("memory_estimation");

@SuppressWarnings({ "unchecked"})
static final ConstructingObjectParser<Response, Void> PARSER =
new ConstructingObjectParser<>(
TYPE.getPreferredName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class DataFrameAnalyticsSource implements Writeable, ToXContentObject {
public static final ParseField QUERY = new ParseField("query");
public static final ParseField _SOURCE = new ParseField("_source");

@SuppressWarnings({ "unchecked"})
public static ConstructingObjectParser<DataFrameAnalyticsSource, Void> createParser(boolean ignoreUnknownFields) {
ConstructingObjectParser<DataFrameAnalyticsSource, Void> parser = new ConstructingObjectParser<>("data_frame_analytics_source",
ignoreUnknownFields, a -> new DataFrameAnalyticsSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class ConfusionMatrix extends AbstractConfusionMatrixMetric {

public static final ParseField NAME = new ParseField("confusion_matrix");

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<ConfusionMatrix, Void> PARSER = new ConstructingObjectParser<>(NAME.getPreferredName(),
a -> new ConfusionMatrix((List<Double>) a[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public class OutlierDetection implements Evaluation {

private static final ParseField METRICS = new ParseField("metrics");

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<OutlierDetection, Void> PARSER = new ConstructingObjectParser<>(
NAME.getPreferredName(), a -> new OutlierDetection((String) a[0], (String) a[1], (List<EvaluationMetric>) a[2]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Precision extends AbstractConfusionMatrixMetric {

public static final ParseField NAME = new ParseField("precision");

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Precision, Void> PARSER = new ConstructingObjectParser<>(NAME.getPreferredName(),
a -> new Precision((List<Double>) a[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class Recall extends AbstractConfusionMatrixMetric {

public static final ParseField NAME = new ParseField("recall");

@SuppressWarnings("unchecked")
private static final ConstructingObjectParser<Recall, Void> PARSER = new ConstructingObjectParser<>(NAME.getPreferredName(),
a -> new Recall((List<Double>) a[0]));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static ValidationLoss fromXContent(XContentParser parser, boolean ignoreU
return createParser(ignoreUnknownFields).apply(parser, null);
}

@SuppressWarnings("unchecked")
private static ConstructingObjectParser<ValidationLoss, Void> createParser(boolean ignoreUnknownFields) {
ConstructingObjectParser<ValidationLoss, Void> parser = new ConstructingObjectParser<>("classification_validation_loss",
ignoreUnknownFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public static FoldValues fromXContent(XContentParser parser, boolean ignoreUnkno
return createParser(ignoreUnknownFields).apply(parser, null);
}

@SuppressWarnings("unchecked")
private static ConstructingObjectParser<FoldValues, Void> createParser(boolean ignoreUnknownFields) {
ConstructingObjectParser<FoldValues, Void> parser = new ConstructingObjectParser<>("fold_values", ignoreUnknownFields,
a -> new FoldValues((int) a[0], (List<Double>) a[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public static ValidationLoss fromXContent(XContentParser parser, boolean ignoreU
return createParser(ignoreUnknownFields).apply(parser, null);
}

@SuppressWarnings("unchecked")
private static ConstructingObjectParser<ValidationLoss, Void> createParser(boolean ignoreUnknownFields) {
ConstructingObjectParser<ValidationLoss, Void> parser = new ConstructingObjectParser<>("regression_validation_loss",
ignoreUnknownFields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

public class RuleScope implements ToXContentObject, Writeable {

@SuppressWarnings("unchecked")
public static ContextParser<Void, RuleScope> parser(boolean ignoreUnknownFields) {
return (p, c) -> {
Map<String, Object> unparsedScope = p.map();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Influence implements ToXContentObject, Writeable {
public static final ConstructingObjectParser<Influence, Void> STRICT_PARSER = createParser(false);
public static final ConstructingObjectParser<Influence, Void> LENIENT_PARSER = createParser(true);

@SuppressWarnings({ "unchecked"})
private static ConstructingObjectParser<Influence, Void> createParser(boolean ignoreUnknownFields) {
ConstructingObjectParser<Influence, Void> parser = new ConstructingObjectParser<>(INFLUENCER.getPreferredName(),
ignoreUnknownFields, a -> new Influence((String) a[0], (List<String>) a[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class RollupJobStatus implements Task.Status, PersistentTaskState {
private static final ParseField CURRENT_POSITION = new ParseField("current_position");
private static final ParseField UPGRADED_DOC_ID = new ParseField("upgraded_doc_id");

@SuppressWarnings("unchecked")
public static final ConstructingObjectParser<RollupJobStatus, Void> PARSER =
new ConstructingObjectParser<>(NAME,
args -> new RollupJobStatus((IndexerState) args[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public void executeAfterRewritingAuthentication(Consumer<StoredContext> consumer
}
}

@SuppressWarnings("unchecked")
private Map<String, Object> rewriteMetadataForApiKeyRoleDescriptors(Version streamVersion, Authentication authentication) {
Map<String, Object> metadata = authentication.getMetadata();
if (authentication.getAuthenticationType() == AuthenticationType.API_KEY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,7 @@ public static List<Setting<?>> getSettings() {

public Map<String, Object> usageStats() {
final ByteSizeValue ram = new ByteSizeValue(ramBytesUsed(), ByteSizeUnit.BYTES);
return new MapBuilder()
.put("count", entryCount())
return new MapBuilder<String, Object>().put("count", entryCount())
.put("memory", ram.toString())
.put("memory_in_bytes", ram.getBytes())
.immutableMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public Fields getTermVectors(int docID) throws IOException {
}

/** Filter a map by a {@link CharacterRunAutomaton} that defines the fields to retain. */
@SuppressWarnings("unchecked")
static Map<String, Object> filter(Map<String, ?> map, CharacterRunAutomaton includeAutomaton, int initialState) {
Map<String, Object> filtered = new HashMap<>();
for (Map.Entry<String, ?> entry : map.entrySet()) {
Expand Down Expand Up @@ -196,6 +197,7 @@ static Map<String, Object> filter(Map<String, ?> map, CharacterRunAutomaton incl
}

/** Filter a list by a {@link CharacterRunAutomaton} that defines the fields to retain. */
@SuppressWarnings("unchecked")
private static List<Object> filter(Iterable<?> iterable, CharacterRunAutomaton includeAutomaton, int initialState) {
List<Object> filtered = new ArrayList<>();
for (Object value : iterable) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static Certificate[] readCertificates(List<Path> certPaths) throws Certif
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
for (Path path : certPaths) {
try (InputStream input = Files.newInputStream(path)) {
certificates.addAll((Collection<Certificate>) certFactory.generateCertificates(input));
certificates.addAll(certFactory.generateCertificates(input));
if (certificates.isEmpty()) {
throw new CertificateException("failed to parse any certificates from [" + path.toAbsolutePath() + "]");
}
Expand All @@ -105,6 +105,7 @@ public static Certificate[] readCertificates(List<Path> certPaths) throws Certif
return certificates.toArray(new Certificate[0]);
}

@SuppressWarnings("unchecked")
public static X509Certificate[] readX509Certificates(List<Path> certPaths) throws CertificateException, IOException {
Collection<X509Certificate> certificates = new ArrayList<>();
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Expand All @@ -118,7 +119,7 @@ public static X509Certificate[] readX509Certificates(List<Path> certPaths) throw

public static List<Certificate> readCertificates(InputStream input) throws CertificateException, IOException {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Collection<Certificate> certificates = (Collection<Certificate>) certFactory.generateCertificates(input);
Collection<? extends Certificate> certificates = certFactory.generateCertificates(input);
return new ArrayList<>(certificates);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class SourceConfig implements Writeable, ToXContentObject {
public static final ConstructingObjectParser<SourceConfig, Void> STRICT_PARSER = createParser(false);
public static final ConstructingObjectParser<SourceConfig, Void> LENIENT_PARSER = createParser(true);

@SuppressWarnings("unchecked")
private static ConstructingObjectParser<SourceConfig, Void> createParser(boolean lenient) {
ConstructingObjectParser<SourceConfig, Void> parser = new ConstructingObjectParser<>("data_frame_config_source",
lenient,
args -> {
@SuppressWarnings("unchecked")
String[] index = ((List<String>)args[0]).toArray(new String[0]);
// default handling: if the user does not specify a query, we default to match_all
QueryConfig queryConfig = args[1] == null ? QueryConfig.matchAll() : (QueryConfig) args[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class LatestConfig implements Writeable, ToXContentObject {
private static final ConstructingObjectParser<LatestConfig, Void> STRICT_PARSER = createParser(false);
private static final ConstructingObjectParser<LatestConfig, Void> LENIENT_PARSER = createParser(true);

@SuppressWarnings("unchecked")
private static ConstructingObjectParser<LatestConfig, Void> createParser(boolean lenient) {
ConstructingObjectParser<LatestConfig, Void> parser =
new ConstructingObjectParser<>(NAME, lenient, args -> new LatestConfig((List<String>) args[0], (String) args[1]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class ActionWrapper implements ToXContentObject {
@Nullable
private final ExecutableCondition condition;
@Nullable
private final ExecutableTransform<Transform, Transform.Result> transform;
private final ExecutableTransform<? extends Transform, ? extends Transform.Result> transform;
private final ActionThrottler throttler;
private final ExecutableAction<? extends Action> action;
@Nullable
Expand All @@ -62,7 +62,7 @@ public class ActionWrapper implements ToXContentObject {

public ActionWrapper(String id, ActionThrottler throttler,
@Nullable ExecutableCondition condition,
@Nullable ExecutableTransform<Transform, Transform.Result> transform,
@Nullable ExecutableTransform<? extends Transform, ? extends Transform.Result> transform,
ExecutableAction<? extends Action> action,
@Nullable String path,
@Nullable Integer maxIterations) {
Expand All @@ -83,7 +83,7 @@ public ExecutableCondition condition() {
return condition;
}

public ExecutableTransform<Transform, Transform.Result> transform() {
public ExecutableTransform<? extends Transform, ? extends Transform.Result> transform() {
return transform;
}

Expand All @@ -109,6 +109,7 @@ public ExecutableAction<? extends Action> action() {
* @param ctx The current watch's context
* @return Never {@code null}
*/
@SuppressWarnings("unchecked")
public ActionWrapperResult execute(WatchExecutionContext ctx) {
ActionWrapperResult result = ctx.actionsResults().get(id);
if (result != null) {
Expand Down Expand Up @@ -175,7 +176,7 @@ public ActionWrapperResult execute(WatchExecutionContext ctx) {
Object object = ObjectPath.eval(path, toMap(ctx));
int runs = 0;
if (object instanceof Collection) {
Collection collection = Collection.class.cast(object);
Collection<?> collection = (Collection<?>) object;
if (collection.isEmpty()) {
throw new ElasticsearchException("foreach object [{}] was an empty list, could not run any action", path);
} else {
Expand Down Expand Up @@ -296,7 +297,7 @@ static ActionWrapper parse(String watchId, String actionId, XContentParser parse
assert parser.currentToken() == XContentParser.Token.START_OBJECT;

ExecutableCondition condition = null;
ExecutableTransform<Transform, Transform.Result> transform = null;
ExecutableTransform<? extends Transform, ? extends Transform.Result> transform = null;
TimeValue throttlePeriod = null;
String path = null;
ExecutableAction<? extends Action> action = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ExecutableAction that = (ExecutableAction) o;
ExecutableAction<? extends Action> that = (ExecutableAction<? extends Action>) o;

return action.equals(that.action);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class WatchSourceBuilder implements ToXContentObject {
private TimeValue defaultThrottlePeriod = null;
private Map<String, Object> metadata;

public WatchSourceBuilder trigger(Trigger.Builder trigger) {
public WatchSourceBuilder trigger(Trigger.Builder<? extends Trigger> trigger) {
return trigger(trigger.build());
}

Expand All @@ -53,7 +53,7 @@ public WatchSourceBuilder trigger(Trigger trigger) {
return this;
}

public WatchSourceBuilder input(Input.Builder input) {
public WatchSourceBuilder input(Input.Builder<? extends Input> input) {
return input(input.build());
}

Expand All @@ -72,7 +72,7 @@ public WatchSourceBuilder transform(Transform transform) {
return this;
}

public WatchSourceBuilder transform(Transform.Builder transform) {
public WatchSourceBuilder transform(Transform.Builder<? extends Transform> transform) {
return transform(transform.build());
}

Expand All @@ -81,23 +81,25 @@ public WatchSourceBuilder defaultThrottlePeriod(TimeValue throttlePeriod) {
return this;
}

public WatchSourceBuilder addAction(String id, Action.Builder action) {
public WatchSourceBuilder addAction(String id, Action.Builder<? extends Action> action) {
return addAction(id, null, null, action.build());
}

public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Action.Builder action) {
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Action.Builder<? extends Action> action) {
return addAction(id, throttlePeriod, null, action.build());
}

public WatchSourceBuilder addAction(String id, Transform.Builder transform, Action.Builder action) {
public WatchSourceBuilder addAction(String id, Transform.Builder<? extends Transform> transform,
Action.Builder<? extends Action> action) {
return addAction(id, null, transform.build(), action.build());
}

public WatchSourceBuilder addAction(String id, Condition condition, Action.Builder action) {
public WatchSourceBuilder addAction(String id, Condition condition, Action.Builder<? extends Action> action) {
return addAction(id, null, condition, null, action.build());
}

public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Transform.Builder transform, Action.Builder action) {
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Transform.Builder<? extends Transform> transform,
Action.Builder<? extends Action> action) {
return addAction(id, throttlePeriod, transform.build(), action.build());
}

Expand All @@ -106,8 +108,8 @@ public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Transfo
return this;
}

public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Condition condition, Transform.Builder transform,
Action.Builder action) {
public WatchSourceBuilder addAction(String id, TimeValue throttlePeriod, Condition condition,
Transform.Builder<? extends Transform> transform, Action.Builder<? extends Action> action) {
return addAction(id, throttlePeriod, condition, transform.build(), action.build());
}

Expand Down
Loading

0 comments on commit 37a24d5

Please sign in to comment.