Skip to content

Commit b374c68

Browse files
committed
Enable compiler warnings for watcher (#75516)
Part of #40366.
1 parent c412076 commit b374c68

File tree

56 files changed

+233
-149
lines changed

Some content is hidden

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

56 files changed

+233
-149
lines changed

x-pack/plugin/watcher/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ archivesBaseName = 'x-pack-watcher'
1616

1717
ext.compactProfile = 'full'
1818

19-
tasks.withType(JavaCompile).configureEach {
20-
options.compilerArgs << "-Xlint:-rawtypes,-unchecked"
21-
}
22-
2319
tasks.named("dependencyLicenses").configure {
2420
mapping from: /owasp-java-html-sanitizer.*/, to: 'owasp-java-html-sanitizer'
2521
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public class Watcher extends Plugin implements SystemIndexPlugin, ScriptPlugin,
243243
protected final Settings settings;
244244
protected final boolean transportClient;
245245
protected final boolean enabled;
246-
protected List<NotificationService> reloadableServices = new ArrayList<>();
246+
protected List<NotificationService<?>> reloadableServices = new ArrayList<>();
247247

248248
public Watcher(final Settings settings) {
249249
this.settings = settings;
@@ -298,7 +298,7 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
298298
reloadableServices.add(pagerDutyService);
299299

300300
TextTemplateEngine templateEngine = new TextTemplateEngine(scriptService);
301-
Map<String, EmailAttachmentParser> emailAttachmentParsers = new HashMap<>();
301+
Map<String, EmailAttachmentParser<?>> emailAttachmentParsers = new HashMap<>();
302302
emailAttachmentParsers.put(HttpEmailAttachementParser.TYPE, new HttpEmailAttachementParser(httpClient, templateEngine));
303303
emailAttachmentParsers.put(DataAttachmentParser.TYPE, new DataAttachmentParser());
304304
emailAttachmentParsers.put(ReportingAttachmentParser.TYPE,
@@ -333,7 +333,7 @@ public Collection<Object> createComponents(Client client, ClusterService cluster
333333
getLicenseState());
334334

335335
// inputs
336-
final Map<String, InputFactory> inputFactories = new HashMap<>();
336+
final Map<String, InputFactory<?, ?, ?>> inputFactories = new HashMap<>();
337337
inputFactories.put(SearchInput.TYPE, new SearchInputFactory(settings, client, xContentRegistry, scriptService));
338338
inputFactories.put(SimpleInput.TYPE, new SimpleInputFactory());
339339
inputFactories.put(HttpInput.TYPE, new HttpInputFactory(settings, httpClient, templateEngine));
@@ -396,7 +396,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
396396
HistoryStore historyStore = new HistoryStore(bulkProcessor, clusterService::state);
397397

398398
// schedulers
399-
final Set<Schedule.Parser> scheduleParsers = new HashSet<>();
399+
final Set<Schedule.Parser<?>> scheduleParsers = new HashSet<>();
400400
scheduleParsers.add(new CronSchedule.Parser());
401401
scheduleParsers.add(new DailySchedule.Parser());
402402
scheduleParsers.add(new HourlySchedule.Parser());
@@ -406,10 +406,10 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
406406
scheduleParsers.add(new YearlySchedule.Parser());
407407
final ScheduleRegistry scheduleRegistry = new ScheduleRegistry(scheduleParsers);
408408

409-
TriggerEngine manualTriggerEngine = new ManualTriggerEngine();
410-
final TriggerEngine configuredTriggerEngine = getTriggerEngine(getClock(), scheduleRegistry);
409+
TriggerEngine<?, ?> manualTriggerEngine = new ManualTriggerEngine();
410+
final TriggerEngine<?, ?> configuredTriggerEngine = getTriggerEngine(getClock(), scheduleRegistry);
411411

412-
final Set<TriggerEngine> triggerEngines = new HashSet<>();
412+
final Set<TriggerEngine<?, ?>> triggerEngines = new HashSet<>();
413413
triggerEngines.add(manualTriggerEngine);
414414
triggerEngines.add(configuredTriggerEngine);
415415
final TriggerService triggerService = new TriggerService(triggerEngines);
@@ -442,7 +442,7 @@ public void afterBulk(long executionId, BulkRequest request, Throwable failure)
442442
configuredTriggerEngine, triggeredWatchStore, watcherSearchTemplateService, slackService, pagerDutyService);
443443
}
444444

445-
protected TriggerEngine getTriggerEngine(Clock clock, ScheduleRegistry scheduleRegistry) {
445+
protected TriggerEngine<?, ?> getTriggerEngine(Clock clock, ScheduleRegistry scheduleRegistry) {
446446
return new TickerScheduleTriggerEngine(settings, scheduleRegistry, clock);
447447
}
448448

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/email/ExecutableEmailAction.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.elasticsearch.xpack.watcher.notification.email.EmailService;
2222
import org.elasticsearch.xpack.watcher.notification.email.HtmlSanitizer;
2323
import org.elasticsearch.xpack.watcher.notification.email.attachment.EmailAttachmentParser;
24+
import org.elasticsearch.xpack.watcher.notification.email.attachment.EmailAttachmentParser.EmailAttachment;
2425
import org.elasticsearch.xpack.watcher.support.Variables;
2526

2627
import java.io.IOException;
@@ -35,10 +36,16 @@ public class ExecutableEmailAction extends ExecutableAction<EmailAction> {
3536
private final EmailService emailService;
3637
private final TextTemplateEngine templateEngine;
3738
private final HtmlSanitizer htmlSanitizer;
38-
private final Map<String, EmailAttachmentParser> emailAttachmentParsers;
39+
private final Map<String, EmailAttachmentParser<? extends EmailAttachment>> emailAttachmentParsers;
3940

40-
public ExecutableEmailAction(EmailAction action, Logger logger, EmailService emailService, TextTemplateEngine templateEngine,
41-
HtmlSanitizer htmlSanitizer, Map<String, EmailAttachmentParser> emailAttachmentParsers) {
41+
public ExecutableEmailAction(
42+
EmailAction action,
43+
Logger logger,
44+
EmailService emailService,
45+
TextTemplateEngine templateEngine,
46+
HtmlSanitizer htmlSanitizer,
47+
Map<String, EmailAttachmentParser<? extends EmailAttachment>> emailAttachmentParsers
48+
) {
4249
super(action, logger);
4350
this.emailService = emailService;
4451
this.templateEngine = templateEngine;
@@ -57,8 +64,10 @@ public Action.Result execute(String actionId, WatchExecutionContext ctx, Payload
5764
}
5865

5966
if (action.getAttachments() != null && action.getAttachments().getAttachments().size() > 0) {
60-
for (EmailAttachmentParser.EmailAttachment emailAttachment : action.getAttachments().getAttachments()) {
61-
EmailAttachmentParser parser = emailAttachmentParsers.get(emailAttachment.type());
67+
for (EmailAttachment emailAttachment : action.getAttachments().getAttachments()) {
68+
@SuppressWarnings("unchecked")
69+
EmailAttachmentParser<EmailAttachment> parser =
70+
(EmailAttachmentParser<EmailAttachment>) emailAttachmentParsers.get(emailAttachment.type());
6271
try {
6372
Attachment attachment = parser.toAttachment(ctx, payload, emailAttachment);
6473
attachments.put(attachment.id(), attachment);

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/index/ExecutableIndexAction.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ public ExecutableIndexAction(IndexAction action, Logger logger, Client client,
5555
this.bulkDefaultTimeout = action.timeout != null ? action.timeout : bulkDefaultTimeout;
5656
}
5757

58+
@SuppressWarnings("unchecked")
5859
@Override
5960
public Action.Result execute(String actionId, WatchExecutionContext ctx, Payload payload) throws Exception {
6061
Map<String, Object> data = payload.data();
6162
if (data.containsKey("_doc")) {
6263
Object doc = data.get("_doc");
6364
if (doc instanceof Iterable) {
64-
return indexBulk((Iterable) doc, actionId, ctx);
65+
return indexBulk((Iterable<?>) doc, actionId, ctx);
6566
}
6667
if (doc.getClass().isArray()) {
6768
return indexBulk(new ArrayObjectIterator.Iterable(doc), actionId, ctx);
@@ -110,7 +111,7 @@ public Action.Result execute(String actionId, WatchExecutionContext ctx, Payload
110111
return new IndexAction.Result(Status.SUCCESS, new XContentSource(bytesReference, XContentType.JSON));
111112
}
112113

113-
Action.Result indexBulk(Iterable list, String actionId, WatchExecutionContext ctx) throws Exception {
114+
Action.Result indexBulk(Iterable<?> list, String actionId, WatchExecutionContext ctx) throws Exception {
114115
if (action.docId != null) {
115116
throw illegalState("could not execute action [{}] of watch [{}]. [doc_id] cannot be used with bulk [_doc] indexing");
116117
}
@@ -126,6 +127,7 @@ Action.Result indexBulk(Iterable list, String actionId, WatchExecutionContext ct
126127
"[_data] field must either hold a Map or an List/Array of Maps", actionId, ctx.watch().id());
127128
}
128129

130+
@SuppressWarnings("unchecked")
129131
Map<String, Object> doc = (Map<String, Object>) item;
130132
if (doc.containsKey(INDEX_FIELD) || doc.containsKey(TYPE_FIELD) || doc.containsKey(ID_FIELD)) {
131133
doc = mutableMap(doc);

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/actions/jira/ExecutableJiraAction.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public Action.Result execute(final String actionId, WatchExecutionContext ctx, P
6363
* Merges the defaults provided as the second parameter into the content of the first
6464
* while applying a {@link Function} on both map key and map value.
6565
*/
66+
@SuppressWarnings("unchecked")
6667
static Map<String, Object> merge(final Map<String, Object> fields, final Map<String, ?> defaults, final Function<String, String> fn) {
6768
if (defaults != null) {
6869
for (Map.Entry<String, ?> defaultEntry : defaults.entrySet()) {
@@ -85,8 +86,8 @@ static Map<String, Object> merge(final Map<String, Object> fields, final Map<Str
8586

8687
} else if (value instanceof List) {
8788
// Apply the transformation to a list of strings
88-
List<Object> newValues = new ArrayList<>(((List) value).size());
89-
for (Object v : (List) value) {
89+
List<Object> newValues = new ArrayList<>(((List<?>) value).size());
90+
for (Object v : (List<?>) value) {
9091
if (v instanceof String) {
9192
newValues.add(fn.apply((String) v));
9293
} else if (v instanceof Map) {

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/common/http/HttpRequest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,10 +292,12 @@ public static HttpRequest parse(XContentParser parser) throws IOException {
292292
pe, currentFieldName);
293293
}
294294
} else if (token == XContentParser.Token.START_OBJECT) {
295+
@SuppressWarnings({"unchecked", "rawtypes"})
296+
final Map<String, String> headers = (Map) WatcherUtils.flattenModel(parser.map());
295297
if (Field.HEADERS.match(currentFieldName, parser.getDeprecationHandler())) {
296-
builder.setHeaders((Map) WatcherUtils.flattenModel(parser.map()));
298+
builder.setHeaders(headers);
297299
} else if (Field.PARAMS.match(currentFieldName, parser.getDeprecationHandler())) {
298-
builder.setParams((Map) WatcherUtils.flattenModel(parser.map()));
300+
builder.setParams(headers);
299301
} else if (Field.BODY.match(currentFieldName, parser.getDeprecationHandler())) {
300302
builder.body(parser.text());
301303
} else {

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/condition/LenientCompare.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class LenientCompare {
2222
// will fail and `false` will be returned.
2323
//
2424
// may return `null` indicating v1 simply doesn't equal v2 (without any order association)
25+
@SuppressWarnings("unchecked")
2526
public static Integer compare(Object v1, Object v2) {
2627
if (Objects.equals(v1, v2)) {
2728
return 0;

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/InputRegistry.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
public class InputRegistry {
2121

22-
private final Map<String, InputFactory> factories;
22+
private final Map<String, InputFactory<?, ?, ?>> factories;
2323

24-
public InputRegistry(Map<String, InputFactory> factories) {
25-
Map<String, InputFactory> map = new HashMap<>(factories);
24+
public InputRegistry(Map<String, InputFactory<?, ?, ?>> factories) {
25+
Map<String, InputFactory<?, ?, ?>> map = new HashMap<>(factories);
2626
map.put(ChainInput.TYPE, new ChainInputFactory(this));
2727
this.factories = Collections.unmodifiableMap(map);
2828
}
@@ -69,7 +69,7 @@ public InputRegistry(Map<String, InputFactory> factories) {
6969
return input;
7070
}
7171

72-
public Map<String, InputFactory> factories() {
72+
public Map<String, InputFactory<?, ?, ?>> factories() {
7373
return factories;
7474
}
7575
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInput.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ private Builder() {
107107
inputs = new ArrayList<>();
108108
}
109109

110-
public Builder add(String name, Input.Builder input) {
110+
public Builder add(String name, Input.Builder<?> input) {
111111
inputs.add(new Tuple<>(name, input.build()));
112112
return this;
113113
}

x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/input/chain/ChainInputFactory.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ public ChainInput parseInput(String watchId, XContentParser parser) throws IOExc
3737

3838
@Override
3939
public ExecutableChainInput createExecutable(ChainInput input) {
40-
List<Tuple<String, ExecutableInput>> executableInputs = new ArrayList<>();
40+
List<Tuple<String, ExecutableInput<?, ?>>> executableInputs = new ArrayList<>();
4141
for (Tuple<String, Input> tuple : input.getInputs()) {
42-
ExecutableInput executableInput = inputRegistry.factories().get(tuple.v2().type()).createExecutable(tuple.v2());
42+
@SuppressWarnings("unchecked")
43+
ExecutableInput<?, ?> executableInput =
44+
((InputFactory<Input, ?, ?>) inputRegistry.factories().get(tuple.v2().type())).createExecutable(tuple.v2());
4345
executableInputs.add(new Tuple<>(tuple.v1(), executableInput));
4446
}
4547

0 commit comments

Comments
 (0)