From b36a8ab141d4095a93f1b036ae1410a0667f5b94 Mon Sep 17 00:00:00 2001 From: Nik Everett Date: Thu, 2 Jan 2020 10:47:38 -0500 Subject: [PATCH] Make some ObjectParsers final (#50471) (#50556) We have about 800 `ObjectParsers` in Elasticsearch, about 700 of which are final. This is *probably* the right way to declare them because in practice we never mutate them after they are built. And we certainly don't change the static reference. Anyway, this adds `final` to a bunch of these parsers, mostly the ones in xpack and their "paired" parsers in the high level rest client. I picked these just to have somewhere to break the up the change so it wouldn't be huge. I found the non-final parsers with this: ``` diff \ <(find . -type f -name '*.java' -exec grep -iHe 'static.*PARSER\s*=' {} \+ | sort) \ <(find . -type f -name '*.java' -exec grep -iHe 'static.*final.*PARSER\s*=' {} \+ | sort) \ 2>&1 | grep '^<' ``` --- .../org/elasticsearch/client/core/MainResponse.java | 3 +-- .../client/indexlifecycle/LifecyclePolicy.java | 2 +- .../client/ml/dataframe/explain/FieldSelection.java | 2 +- .../client/security/CreateApiKeyResponse.java | 2 +- .../client/security/GetApiKeyResponse.java | 7 ++++--- .../client/security/InvalidateApiKeyResponse.java | 10 ++++++---- .../elasticsearch/client/security/support/ApiKey.java | 2 +- .../aggregations/matrix/stats/ParsedMatrixStats.java | 2 +- .../xpack/ccr/action/ShardFollowTask.java | 2 +- .../elasticsearch/xpack/core/ilm/LifecyclePolicy.java | 2 +- .../xpack/core/ml/action/CloseJobAction.java | 2 +- .../xpack/core/ml/action/IsolateDatafeedAction.java | 3 +-- .../xpack/core/ml/action/OpenJobAction.java | 2 +- .../core/ml/action/RevertModelSnapshotAction.java | 3 +-- .../core/ml/action/StartDataFrameAnalyticsAction.java | 2 +- .../xpack/core/ml/action/StartDatafeedAction.java | 6 +++++- .../xpack/core/ml/action/StopDatafeedAction.java | 3 +-- .../core/ml/dataframe/explain/FieldSelection.java | 3 ++- .../xpack/core/security/action/ApiKey.java | 2 +- .../core/security/action/CreateApiKeyResponse.java | 2 +- .../xpack/core/security/action/GetApiKeyResponse.java | 2 +- .../security/action/InvalidateApiKeyResponse.java | 11 +++++++---- .../core/transform/action/PreviewTransformAction.java | 2 +- 23 files changed, 42 insertions(+), 35 deletions(-) diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/MainResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/MainResponse.java index 96810fe8c8b..09fc2b49a01 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/core/MainResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/core/MainResponse.java @@ -27,8 +27,7 @@ import java.util.Objects; public class MainResponse { - @SuppressWarnings("unchecked") - private static ConstructingObjectParser PARSER = + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(MainResponse.class.getName(), true, args -> { return new MainResponse((String) args[0], (Version) args[1], (String) args[2], (String) args[3], (String) args[4]); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/LifecyclePolicy.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/LifecyclePolicy.java index 9032afd7ba4..0e308d8bedf 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/LifecyclePolicy.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/indexlifecycle/LifecyclePolicy.java @@ -44,7 +44,7 @@ public class LifecyclePolicy implements ToXContentObject { static final ParseField PHASES_FIELD = new ParseField("phases"); @SuppressWarnings("unchecked") - public static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("lifecycle_policy", true, + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("lifecycle_policy", true, (a, name) -> { List phases = (List) a[0]; Map phaseMap = phases.stream().collect(Collectors.toMap(Phase::getName, Function.identity())); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/ml/dataframe/explain/FieldSelection.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/ml/dataframe/explain/FieldSelection.java index 4483b6fa5e0..997fa872769 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/ml/dataframe/explain/FieldSelection.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/ml/dataframe/explain/FieldSelection.java @@ -57,7 +57,7 @@ public class FieldSelection implements ToXContentObject { } @SuppressWarnings("unchecked") - public static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("field_selection", true, + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("field_selection", true, a -> new FieldSelection((String) a[0], new HashSet<>((List) a[1]), (boolean) a[2], (boolean) a[3], (FeatureType) a[4], (String) a[5])); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/CreateApiKeyResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/CreateApiKeyResponse.java index 9c503723740..0e99f0476ba 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/CreateApiKeyResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/CreateApiKeyResponse.java @@ -89,7 +89,7 @@ public final class CreateApiKeyResponse { && Objects.equals(expiration, other.expiration); } - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("create_api_key_response", + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("create_api_key_response", args -> new CreateApiKeyResponse((String) args[0], (String) args[1], new SecureString((String) args[2]), (args[3] == null) ? null : Instant.ofEpochMilli((Long) args[3]))); static { diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/GetApiKeyResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/GetApiKeyResponse.java index 58e3e8effbb..306866bad69 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/GetApiKeyResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/GetApiKeyResponse.java @@ -73,9 +73,10 @@ public final class GetApiKeyResponse { } @SuppressWarnings("unchecked") - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("get_api_key_response", args -> { - return (args[0] == null) ? GetApiKeyResponse.emptyResponse() : new GetApiKeyResponse((List) args[0]); - }); + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "get_api_key_response", + args -> { return (args[0] == null) ? GetApiKeyResponse.emptyResponse() : new GetApiKeyResponse((List) args[0]); } + ); static { PARSER.declareObjectArray(optionalConstructorArg(), (p, c) -> ApiKey.fromXContent(p), new ParseField("api_keys")); } diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/InvalidateApiKeyResponse.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/InvalidateApiKeyResponse.java index 48df9d0f7f1..14deac35050 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/InvalidateApiKeyResponse.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/InvalidateApiKeyResponse.java @@ -74,10 +74,12 @@ public final class InvalidateApiKeyResponse { } @SuppressWarnings("unchecked") - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("invalidate_api_key_response", - args -> { - return new InvalidateApiKeyResponse((List) args[0], (List) args[1], (List) args[3]); - }); + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "invalidate_api_key_response", + args -> { + return new InvalidateApiKeyResponse((List) args[0], (List) args[1], (List) args[3]); + } + ); static { PARSER.declareStringArray(constructorArg(), new ParseField("invalidated_api_keys")); PARSER.declareStringArray(constructorArg(), new ParseField("previously_invalidated_api_keys")); diff --git a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/support/ApiKey.java b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/support/ApiKey.java index d7065a311a5..747010fd09f 100644 --- a/client/rest-high-level/src/main/java/org/elasticsearch/client/security/support/ApiKey.java +++ b/client/rest-high-level/src/main/java/org/elasticsearch/client/security/support/ApiKey.java @@ -127,7 +127,7 @@ public final class ApiKey { && Objects.equals(realm, other.realm); } - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("api_key", args -> { + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("api_key", args -> { return new ApiKey((String) args[0], (String) args[1], Instant.ofEpochMilli((Long) args[2]), (args[3] == null) ? null : Instant.ofEpochMilli((Long) args[3]), (Boolean) args[4], (String) args[5], (String) args[6]); }); diff --git a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/ParsedMatrixStats.java b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/ParsedMatrixStats.java index a0b9224ad0d..ba28e0b0ee3 100644 --- a/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/ParsedMatrixStats.java +++ b/modules/aggs-matrix-stats/src/main/java/org/elasticsearch/search/aggregations/matrix/stats/ParsedMatrixStats.java @@ -151,7 +151,7 @@ public class ParsedMatrixStats extends ParsedAggregation implements MatrixStats return values.get(fieldName); } - private static ObjectParser PARSER = + private static final ObjectParser PARSER = new ObjectParser<>(ParsedMatrixStats.class.getSimpleName(), true, ParsedMatrixStats::new); static { declareAggregationFields(PARSER); diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java index 1c4fc84da70..d0a6fff63ad 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/ShardFollowTask.java @@ -46,7 +46,7 @@ public class ShardFollowTask extends ImmutableFollowParameters implements XPackP private static final ParseField HEADERS = new ParseField("headers"); @SuppressWarnings("unchecked") - private static ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, + private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>(NAME, (a) -> new ShardFollowTask((String) a[0], new ShardId((String) a[1], (String) a[2], (int) a[3]), new ShardId((String) a[4], (String) a[5], (int) a[6]), (Integer) a[7], (Integer) a[8], (Integer) a[9], (Integer) a[10], (ByteSizeValue) a[11], (ByteSizeValue) a[12], diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java index 7c810d12552..aa16473f211 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/LifecyclePolicy.java @@ -47,7 +47,7 @@ public class LifecyclePolicy extends AbstractDiffable public static final ParseField PHASES_FIELD = new ParseField("phases"); @SuppressWarnings("unchecked") - public static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("lifecycle_policy", false, + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("lifecycle_policy", false, (a, name) -> { List phases = (List) a[0]; Map phaseMap = phases.stream().collect(Collectors.toMap(Phase::getName, Function.identity())); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java index 88d4c4b4e80..e05b21bb79b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/CloseJobAction.java @@ -41,7 +41,7 @@ public class CloseJobAction extends ActionType { public static final ParseField TIMEOUT = new ParseField("timeout"); public static final ParseField FORCE = new ParseField("force"); public static final ParseField ALLOW_NO_JOBS = new ParseField("allow_no_jobs"); - public static ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); + public static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); static { PARSER.declareString(Request::setJobId, Job.ID); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java index a3d8088d138..4187b347a8d 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/IsolateDatafeedAction.java @@ -46,8 +46,7 @@ public class IsolateDatafeedAction extends ActionType implements ToXContentObject { - public static ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); - + public static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); static { PARSER.declareString((request, datafeedId) -> request.datafeedId = datafeedId, DatafeedConfig.ID); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java index 55c8b764b0a..d455a165daf 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/OpenJobAction.java @@ -124,7 +124,7 @@ public class OpenJobAction extends ActionType { public static final ParseField TIMEOUT = new ParseField("timeout"); public static final ParseField JOB = new ParseField("job"); - public static ObjectParser PARSER = new ObjectParser<>(MlTasks.JOB_TASK_NAME, true, JobParams::new); + public static final ObjectParser PARSER = new ObjectParser<>(MlTasks.JOB_TASK_NAME, true, JobParams::new); static { PARSER.declareString(JobParams::setJobId, Job.ID); PARSER.declareString((params, val) -> diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotAction.java index 9550d6fa902..b2488a70335 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/RevertModelSnapshotAction.java @@ -43,8 +43,7 @@ public class RevertModelSnapshotAction extends ActionType PARSER = new ObjectParser<>(NAME, Request::new); - + private static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); static { PARSER.declareString((request, jobId) -> request.jobId = jobId, Job.ID); PARSER.declareString((request, snapshotId) -> request.snapshotId = snapshotId, SNAPSHOT_ID); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java index f9f17316b0d..3d1207a939b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDataFrameAnalyticsAction.java @@ -157,7 +157,7 @@ public class StartDataFrameAnalyticsAction extends ActionType PARSER = new ConstructingObjectParser<>( + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( MlTasks.DATA_FRAME_ANALYTICS_TASK_NAME, true, a -> new TaskParams((String) a[0], (String) a[1], (List) a[2], (Boolean) a[3])); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java index cb80f93234f..33102cf93a9 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StartDatafeedAction.java @@ -136,7 +136,11 @@ public class StartDatafeedAction extends ActionType { public static final ParseField INDICES = new ParseField("indices"); - public static ObjectParser PARSER = new ObjectParser<>(MlTasks.DATAFEED_TASK_NAME, true, DatafeedParams::new); + public static final ObjectParser PARSER = new ObjectParser<>( + MlTasks.DATAFEED_TASK_NAME, + true, + DatafeedParams::new + ); static { PARSER.declareString((params, datafeedId) -> params.datafeedId = datafeedId, DatafeedConfig.ID); PARSER.declareString((params, startTime) -> params.startTime = parseDateOrThrow( diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java index 2dd0b05b49f..851eb01487a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/action/StopDatafeedAction.java @@ -45,8 +45,7 @@ public class StopDatafeedAction extends ActionType public static final ParseField FORCE = new ParseField("force"); public static final ParseField ALLOW_NO_DATAFEEDS = new ParseField("allow_no_datafeeds"); - public static ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); - + public static final ObjectParser PARSER = new ObjectParser<>(NAME, Request::new); static { PARSER.declareString((request, datafeedId) -> request.datafeedId = datafeedId, DatafeedConfig.ID); PARSER.declareString((request, val) -> diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/explain/FieldSelection.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/explain/FieldSelection.java index 57fae51d366..609cec37345 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/explain/FieldSelection.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ml/dataframe/explain/FieldSelection.java @@ -46,7 +46,8 @@ public class FieldSelection implements ToXContentObject, Writeable { } } - public static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("field_selection", + @SuppressWarnings("unchecked") + public static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("field_selection", a -> new FieldSelection((String) a[0], new HashSet<>((List) a[1]), (boolean) a[2], (boolean) a[3], (FeatureType) a[4], (String) a[5])); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/ApiKey.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/ApiKey.java index 214881f34ea..9c6d6a9f9b6 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/ApiKey.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/ApiKey.java @@ -147,7 +147,7 @@ public final class ApiKey implements ToXContentObject, Writeable { && Objects.equals(realm, other.realm); } - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("api_key", args -> { + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("api_key", args -> { return new ApiKey((String) args[0], (String) args[1], Instant.ofEpochMilli((Long) args[2]), (args[3] == null) ? null : Instant.ofEpochMilli((Long) args[3]), (Boolean) args[4], (String) args[5], (String) args[6]); }); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java index 56c855fe26b..2fe2c36f9ce 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/CreateApiKeyResponse.java @@ -31,7 +31,7 @@ import static org.elasticsearch.common.xcontent.ConstructingObjectParser.optiona */ public final class CreateApiKeyResponse extends ActionResponse implements ToXContentObject { - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("create_api_key_response", + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("create_api_key_response", args -> new CreateApiKeyResponse((String) args[0], (String) args[1], new SecureString((String) args[2]), (args[3] == null) ? null : Instant.ofEpochMilli((Long) args[3]))); static { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/GetApiKeyResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/GetApiKeyResponse.java index f4765721819..19c826da524 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/GetApiKeyResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/GetApiKeyResponse.java @@ -63,7 +63,7 @@ public final class GetApiKeyResponse extends ActionResponse implements ToXConten } @SuppressWarnings("unchecked") - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("get_api_key_response", args -> { + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>("get_api_key_response", args -> { return (args[0] == null) ? GetApiKeyResponse.emptyResponse() : new GetApiKeyResponse((List) args[0]); }); static { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyResponse.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyResponse.java index 39850c0fff8..d6b03d6e5fd 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyResponse.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/InvalidateApiKeyResponse.java @@ -109,10 +109,13 @@ public final class InvalidateApiKeyResponse extends ActionResponse implements To out.writeCollection(errors, StreamOutput::writeException); } - static ConstructingObjectParser PARSER = new ConstructingObjectParser<>("invalidate_api_key_response", - args -> { - return new InvalidateApiKeyResponse((List) args[0], (List) args[1], (List) args[3]); - }); + @SuppressWarnings("unchecked") + static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( + "invalidate_api_key_response", + args -> { + return new InvalidateApiKeyResponse((List) args[0], (List) args[1], (List) args[3]); + } + ); static { PARSER.declareStringArray(constructorArg(), new ParseField("invalidated_api_keys")); PARSER.declareStringArray(constructorArg(), new ParseField("previously_invalidated_api_keys")); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/PreviewTransformAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/PreviewTransformAction.java index b8f11d7fcbf..7cc4b73b79b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/PreviewTransformAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/transform/action/PreviewTransformAction.java @@ -146,7 +146,7 @@ public class PreviewTransformAction extends ActionType PARSER = new ObjectParser<>("data_frame_transform_preview", Response::new); + static final ObjectParser PARSER = new ObjectParser<>("data_frame_transform_preview", Response::new); static { PARSER.declareObjectArray(Response::setDocs, (p, c) -> p.mapOrdered(), PREVIEW); PARSER.declareObject(Response::setMappings, (p, c) -> p.mapOrdered(), MAPPINGS);