diff --git a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java index c5004f7c995d0..480801ae7ba38 100644 --- a/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java +++ b/x-pack/plugin/ccr/src/main/java/org/elasticsearch/xpack/ccr/action/TransportFollowStatsAction.java @@ -103,8 +103,7 @@ protected void processTasks(final FollowStatsAction.StatsRequest request, final final Set followerIndices = findFollowerIndicesFromShardFollowTasks(state, request.indices()); for (final Task task : taskManager.getTasks().values()) { - if (task instanceof ShardFollowNodeTask) { - final ShardFollowNodeTask shardFollowNodeTask = (ShardFollowNodeTask) task; + if (task instanceof final ShardFollowNodeTask shardFollowNodeTask) { if (followerIndices.contains(shardFollowNodeTask.getFollowShardId().getIndexName())) { operation.accept(shardFollowNodeTask); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java index 227857924a2cf..1b640164d54b5 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authc/support/mapper/expressiondsl/FieldExpression.java @@ -118,8 +118,7 @@ public FieldValue(Object value) { } private static CharacterRunAutomaton buildAutomaton(Object value) { - if (value instanceof String) { - final String str = (String) value; + if (value instanceof final String str) { if (Regex.isSimpleMatchPattern(str) || Automatons.isLuceneRegex(str)) { return new CharacterRunAutomaton(Automatons.patterns(str)); } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java index e65d933f38c0a..c70f2a05bfe93 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/permission/ClusterPermission.java @@ -248,8 +248,7 @@ protected boolean extendedCheck(String action, TransportRequest request, Authent @Override protected boolean doImplies(final ActionBasedPermissionCheck permissionCheck) { - if (permissionCheck instanceof ActionRequestBasedPermissionCheck) { - final ActionRequestBasedPermissionCheck otherCheck = (ActionRequestBasedPermissionCheck) permissionCheck; + if (permissionCheck instanceof final ActionRequestBasedPermissionCheck otherCheck) { return this.clusterPrivilege.equals(otherCheck.clusterPrivilege); } return false; diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ConfigurableClusterPrivileges.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ConfigurableClusterPrivileges.java index 75bd0b448ebe8..82f7a6062013a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ConfigurableClusterPrivileges.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ConfigurableClusterPrivileges.java @@ -147,8 +147,7 @@ public ManageApplicationPrivileges(Set applicationNames) { this.applicationNames = Collections.unmodifiableSet(applicationNames); this.applicationPredicate = StringMatcher.of(applicationNames); this.requestPredicate = request -> { - if (request instanceof ApplicationPrivilegesRequest) { - final ApplicationPrivilegesRequest privRequest = (ApplicationPrivilegesRequest) request; + if (request instanceof final ApplicationPrivilegesRequest privRequest) { final Collection requestApplicationNames = privRequest.getApplicationNames(); return requestApplicationNames.isEmpty() ? this.applicationNames.contains("*") diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java index aa19d63221ec1..9c50dcd111960 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/authz/privilege/ManageOwnApiKeyClusterPrivilege.java @@ -59,8 +59,7 @@ private ManageOwnClusterPermissionCheck() { protected boolean extendedCheck(String action, TransportRequest request, Authentication authentication) { if (request instanceof CreateApiKeyRequest) { return true; - } else if (request instanceof GetApiKeyRequest) { - final GetApiKeyRequest getApiKeyRequest = (GetApiKeyRequest) request; + } else if (request instanceof final GetApiKeyRequest getApiKeyRequest) { return checkIfUserIsOwnerOfApiKeys( authentication, getApiKeyRequest.getApiKeyId(), @@ -68,8 +67,7 @@ protected boolean extendedCheck(String action, TransportRequest request, Authent getApiKeyRequest.getRealmName(), getApiKeyRequest.ownedByAuthenticatedUser() ); - } else if (request instanceof InvalidateApiKeyRequest) { - final InvalidateApiKeyRequest invalidateApiKeyRequest = (InvalidateApiKeyRequest) request; + } else if (request instanceof final InvalidateApiKeyRequest invalidateApiKeyRequest) { final String[] apiKeyIds = invalidateApiKeyRequest.getIds(); if (apiKeyIds == null) { return checkIfUserIsOwnerOfApiKeys( @@ -91,8 +89,7 @@ protected boolean extendedCheck(String action, TransportRequest request, Authent ) ); } - } else if (request instanceof QueryApiKeyRequest) { - final QueryApiKeyRequest queryApiKeyRequest = (QueryApiKeyRequest) request; + } else if (request instanceof final QueryApiKeyRequest queryApiKeyRequest) { return queryApiKeyRequest.isFilterForCurrentUser(); } throw new IllegalArgumentException( diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/test/TestMatchers.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/test/TestMatchers.java index 674d0c3c0243b..831b884259d9e 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/test/TestMatchers.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/test/TestMatchers.java @@ -47,8 +47,7 @@ public void describeTo(Description description) { @Override public boolean matches(Object actual) { - if (actual instanceof Throwable) { - final Throwable throwable = (Throwable) actual; + if (actual instanceof final Throwable throwable) { return messageMatcher.matches(throwable.getMessage()); } else { return false; diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java index 84927b415c9c8..0dad202d4ea4e 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/ApiKeyService.java @@ -1141,8 +1141,7 @@ public void onFailure(Exception e) { */ private E traceLog(String action, String identifier, E exception) { if (logger.isTraceEnabled()) { - if (exception instanceof ElasticsearchException) { - final ElasticsearchException esEx = (ElasticsearchException) exception; + if (exception instanceof final ElasticsearchException esEx) { final Object detail = esEx.getHeader("error_description"); if (detail != null) { logger.trace(() -> new ParameterizedMessage("Failure in [{}] for id [{}] - [{}]", action, identifier, detail), esEx); @@ -1161,8 +1160,7 @@ private E traceLog(String action, String identifier, E exc */ private E traceLog(String action, E exception) { if (logger.isTraceEnabled()) { - if (exception instanceof ElasticsearchException) { - final ElasticsearchException esEx = (ElasticsearchException) exception; + if (exception instanceof final ElasticsearchException esEx) { final Object detail = esEx.getHeader("error_description"); if (detail != null) { logger.trace(() -> new ParameterizedMessage("Failure in [{}] - [{}]", action, detail), esEx); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/AuthenticatorChain.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/AuthenticatorChain.java index 425c239ef8d24..9703490aee16f 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/AuthenticatorChain.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/AuthenticatorChain.java @@ -173,9 +173,8 @@ private BiConsumer E traceLog(String action, String identifier, E exception) { if (logger.isTraceEnabled()) { - if (exception instanceof ElasticsearchException) { - final ElasticsearchException esEx = (ElasticsearchException) exception; + if (exception instanceof final ElasticsearchException esEx) { final Object detail = esEx.getHeader("error_description"); if (detail != null) { logger.trace(() -> new ParameterizedMessage("Failure in [{}] for id [{}] - [{}]", action, identifier, detail), esEx); @@ -2212,8 +2211,7 @@ private E traceLog(String action, String identifier, E exc */ private E traceLog(String action, E exception) { if (logger.isTraceEnabled()) { - if (exception instanceof ElasticsearchException) { - final ElasticsearchException esEx = (ElasticsearchException) exception; + if (exception instanceof final ElasticsearchException esEx) { final Object detail = esEx.getHeader("error_description"); if (detail != null) { logger.trace(() -> new ParameterizedMessage("Failure in [{}] - [{}]", action, detail), esEx); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java index 04eb24da827a3..7a8ef774dfea3 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authz/IndicesAndAliasesResolver.java @@ -199,8 +199,7 @@ ResolvedIndices resolveIndicesAndAliases( assert indicesRequest.indices() == null || indicesRequest.indices().length == 0 : "indices are: " + Arrays.toString(indicesRequest.indices()); // Arrays.toString() can handle null values - all good resolvedIndicesBuilder.addLocal(getPutMappingIndexOrAlias((PutMappingRequest) indicesRequest, authorizedIndices, metadata)); - } else if (indicesRequest instanceof IndicesRequest.Replaceable) { - final IndicesRequest.Replaceable replaceable = (IndicesRequest.Replaceable) indicesRequest; + } else if (indicesRequest instanceof final IndicesRequest.Replaceable replaceable) { final IndicesOptions indicesOptions = indicesRequest.indicesOptions(); final boolean replaceWildcards = indicesOptions.expandWildcardsOpen() || indicesOptions.expandWildcardsClosed(); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilder.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilder.java index 6c6d8b4b31a16..739c52e564014 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilder.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/ApiKeyBoolQueryBuilder.java @@ -73,8 +73,7 @@ public static ApiKeyBoolQueryBuilder build(QueryBuilder queryBuilder, @Nullable } private static QueryBuilder doProcess(QueryBuilder qb) { - if (qb instanceof BoolQueryBuilder) { - final BoolQueryBuilder query = (BoolQueryBuilder) qb; + if (qb instanceof final BoolQueryBuilder query) { final BoolQueryBuilder newQuery = QueryBuilders.boolQuery() .minimumShouldMatch(query.minimumShouldMatch()) .adjustPureNegative(query.adjustPureNegative()); @@ -87,29 +86,24 @@ private static QueryBuilder doProcess(QueryBuilder qb) { return qb; } else if (qb instanceof IdsQueryBuilder) { return qb; - } else if (qb instanceof TermQueryBuilder) { - final TermQueryBuilder query = (TermQueryBuilder) qb; + } else if (qb instanceof final TermQueryBuilder query) { final String translatedFieldName = ApiKeyFieldNameTranslators.translate(query.fieldName()); return QueryBuilders.termQuery(translatedFieldName, query.value()).caseInsensitive(query.caseInsensitive()); - } else if (qb instanceof TermsQueryBuilder) { - final TermsQueryBuilder query = (TermsQueryBuilder) qb; + } else if (qb instanceof final TermsQueryBuilder query) { if (query.termsLookup() != null) { throw new IllegalArgumentException("terms query with terms lookup is not supported for API Key query"); } final String translatedFieldName = ApiKeyFieldNameTranslators.translate(query.fieldName()); return QueryBuilders.termsQuery(translatedFieldName, query.getValues()); - } else if (qb instanceof PrefixQueryBuilder) { - final PrefixQueryBuilder query = (PrefixQueryBuilder) qb; + } else if (qb instanceof final PrefixQueryBuilder query) { final String translatedFieldName = ApiKeyFieldNameTranslators.translate(query.fieldName()); return QueryBuilders.prefixQuery(translatedFieldName, query.value()).caseInsensitive(query.caseInsensitive()); - } else if (qb instanceof WildcardQueryBuilder) { - final WildcardQueryBuilder query = (WildcardQueryBuilder) qb; + } else if (qb instanceof final WildcardQueryBuilder query) { final String translatedFieldName = ApiKeyFieldNameTranslators.translate(query.fieldName()); return QueryBuilders.wildcardQuery(translatedFieldName, query.value()) .caseInsensitive(query.caseInsensitive()) .rewrite(query.rewrite()); - } else if (qb instanceof RangeQueryBuilder) { - final RangeQueryBuilder query = (RangeQueryBuilder) qb; + } else if (qb instanceof final RangeQueryBuilder query) { final String translatedFieldName = ApiKeyFieldNameTranslators.translate(query.fieldName()); if (query.relation() != null) { throw new IllegalArgumentException("range query with relation is not supported for API Key query"); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmSettingsTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmSettingsTests.java index 0dcc46efe97b3..58c3981652f26 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmSettingsTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/RealmSettingsTests.java @@ -282,8 +282,7 @@ private MockSecureSettings normaliseSecureSettingPrefix(String prefix, SecureSet if (settings == null) { return null; } - if (settings instanceof MockSecureSettings) { - final MockSecureSettings source = (MockSecureSettings) settings; + if (settings instanceof final MockSecureSettings source) { final MockSecureSettings target = new MockSecureSettings(); for (String key : settings.getSettingNames()) { target.setString(prefix + key, source.getString(key).toString()); diff --git a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/IndexServiceAccountTokenStoreTests.java b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/IndexServiceAccountTokenStoreTests.java index cad42d428e41d..0761134d0de09 100644 --- a/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/IndexServiceAccountTokenStoreTests.java +++ b/x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/authc/service/IndexServiceAccountTokenStoreTests.java @@ -321,8 +321,7 @@ public void testFindTokensForException() { public void testDeleteToken() { final AtomicBoolean cacheCleared = new AtomicBoolean(false); responseProviderHolder.set((r, l) -> { - if (r instanceof DeleteRequest) { - final DeleteRequest dr = (DeleteRequest) r; + if (r instanceof final DeleteRequest dr) { final boolean found = dr.id().equals(SERVICE_ACCOUNT_TOKEN_DOC_TYPE + "-elastic/fleet-server/token1"); l.onResponse( new DeleteResponse( diff --git a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/TransformAggregations.java b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/TransformAggregations.java index 95ece2ac49703..c5936a4a41277 100644 --- a/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/TransformAggregations.java +++ b/x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/transforms/pivot/TransformAggregations.java @@ -233,8 +233,7 @@ public static Tuple, Map> getAggregationInpu ); } - if (agg instanceof ValuesSourceAggregationBuilder) { - ValuesSourceAggregationBuilder valueSourceAggregation = (ValuesSourceAggregationBuilder) agg; + if (agg instanceof ValuesSourceAggregationBuilder valueSourceAggregation) { return new Tuple<>( Collections.singletonMap(valueSourceAggregation.getName(), valueSourceAggregation.field()), Collections.singletonMap(valueSourceAggregation.getName(), valueSourceAggregation.getType())