diff options
20 files changed, 69 insertions, 81 deletions
diff --git a/server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/CallbackHandlerImpl.java b/server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/CallbackHandlerImpl.java index 472a1821cf8..08b267d3478 100644 --- a/server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/CallbackHandlerImpl.java +++ b/server/sonar-auth-ldap/src/main/java/org/sonar/auth/ldap/CallbackHandlerImpl.java @@ -41,13 +41,11 @@ public class CallbackHandlerImpl implements CallbackHandler { @Override public void handle(Callback[] callbacks) throws UnsupportedCallbackException, IOException { for (Callback callBack : callbacks) { - if (callBack instanceof NameCallback) { + if (callBack instanceof NameCallback nameCallback) { // Handles username callback - NameCallback nameCallback = (NameCallback) callBack; nameCallback.setName(name); - } else if (callBack instanceof PasswordCallback) { + } else if (callBack instanceof PasswordCallback passwordCallback) { // Handles password callback - PasswordCallback passwordCallback = (PasswordCallback) callBack; passwordCallback.setPassword(password.toCharArray()); } else { throw new UnsupportedCallbackException(callBack, "Callback not supported"); diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java index 0049d77c855..b3aeae90cef 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/VisitorsCrawler.java @@ -149,10 +149,10 @@ public class VisitorsCrawler implements ComponentCrawler { @Override public VisitorWrapper apply(@Nonnull ComponentVisitor componentVisitor) { - if (componentVisitor instanceof TypeAwareVisitor) { - return new TypeAwareVisitorWrapper((TypeAwareVisitor) componentVisitor); - } else if (componentVisitor instanceof PathAwareVisitor) { - return new PathAwareVisitorWrapper((PathAwareVisitor) componentVisitor); + if (componentVisitor instanceof TypeAwareVisitor typeAwareVisitor) { + return new TypeAwareVisitorWrapper(typeAwareVisitor); + } else if (componentVisitor instanceof PathAwareVisitor pathAwareVisitor) { + return new PathAwareVisitorWrapper(pathAwareVisitor); } else { throw new IllegalArgumentException("Only TypeAwareVisitor and PathAwareVisitor can be used"); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java index 1f106ca1bfc..18dda44d20e 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/duplication/Duplication.java @@ -147,11 +147,11 @@ public final class Duplication { if (duplicate instanceof InnerDuplicate) { return ""; } - if (duplicate instanceof InProjectDuplicate) { - return ((InProjectDuplicate) duplicate).getFile().getKey(); + if (duplicate instanceof InProjectDuplicate inProjectDuplicate) { + return inProjectDuplicate.getFile().getKey(); } - if (duplicate instanceof CrossProjectDuplicate) { - return ((CrossProjectDuplicate) duplicate).getFileKey(); + if (duplicate instanceof CrossProjectDuplicate crossProjectDuplicate) { + return crossProjectDuplicate.getFileKey(); } throw new IllegalArgumentException("Unsupported type of Duplicate " + duplicate.getClass().getName()); } diff --git a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java index 90aa22d9ede..3561fd0d9b4 100644 --- a/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java +++ b/server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/step/PersistDuplicationDataStep.java @@ -159,15 +159,15 @@ public class PersistDuplicationDataStep implements ComputationStep { if (duplicate instanceof InnerDuplicate) { // Duplication is on the same file appendDuplication(xml, componentDbKey, duplicate); - } else if (duplicate instanceof InExtendedProjectDuplicate) { + } else if (duplicate instanceof InExtendedProjectDuplicate inExtendedProjectDuplicate) { // Duplication is on a different file that is not saved in the DB - appendDuplication(xml, ((InExtendedProjectDuplicate) duplicate).getFile().getKey(), duplicate.getTextBlock(), true); - } else if (duplicate instanceof InProjectDuplicate) { + appendDuplication(xml, inExtendedProjectDuplicate.getFile().getKey(), duplicate.getTextBlock(), true); + } else if (duplicate instanceof InProjectDuplicate inProjectDuplicate) { // Duplication is on a different file - appendDuplication(xml, ((InProjectDuplicate) duplicate).getFile().getKey(), duplicate); - } else if (duplicate instanceof CrossProjectDuplicate) { + appendDuplication(xml, inProjectDuplicate.getFile().getKey(), duplicate); + } else if (duplicate instanceof CrossProjectDuplicate crossProjectDuplicate) { // Only componentKey is set for cross project duplications - String crossProjectComponentKey = ((CrossProjectDuplicate) duplicate).getFileKey(); + String crossProjectComponentKey = crossProjectDuplicate.getFileKey(); appendDuplication(xml, crossProjectComponentKey, duplicate); } else { throw new IllegalArgumentException("Unsupported type of Duplicate " + duplicate.getClass().getName()); diff --git a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTaskInterruptedException.java b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTaskInterruptedException.java index 0c50abd1087..5ab9674b1e8 100644 --- a/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTaskInterruptedException.java +++ b/server/sonar-ce-task/src/main/java/org/sonar/ce/task/CeTaskInterruptedException.java @@ -37,8 +37,8 @@ public abstract class CeTaskInterruptedException extends RuntimeException { } public static Optional<CeTaskInterruptedException> isTaskInterruptedException(Throwable e) { - if (e instanceof CeTaskInterruptedException) { - return Optional.of((CeTaskInterruptedException) e); + if (e instanceof CeTaskInterruptedException ceTaskInterruptedException) { + return Optional.of(ceTaskInterruptedException); } return isCauseInterruptedException(e); } @@ -48,8 +48,8 @@ public abstract class CeTaskInterruptedException extends RuntimeException { if (cause == null || cause == e) { return Optional.empty(); } - if (cause instanceof CeTaskInterruptedException) { - return Optional.of((CeTaskInterruptedException) cause); + if (cause instanceof CeTaskInterruptedException ceTaskInterruptedException) { + return Optional.of(ceTaskInterruptedException); } return isCauseInterruptedException(cause); } diff --git a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java index c235664cb2b..69d319c7aa9 100644 --- a/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java +++ b/server/sonar-ce/src/main/java/org/sonar/ce/queue/InternalCeQueueImpl.java @@ -154,8 +154,8 @@ public class InternalCeQueueImpl extends CeQueueImpl implements InternalCeQueue if (stacktrace != null) { activityDto.setErrorStacktrace(stacktrace); } - if (error instanceof TypedException) { - activityDto.setErrorType(((TypedException) error).getType()); + if (error instanceof TypedException typedException) { + activityDto.setErrorType(typedException.getType()); } } diff --git a/server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java b/server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java index 4b22911f5d7..eb9d72d8ba9 100644 --- a/server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java +++ b/server/sonar-main/src/main/java/org/sonar/application/ProcessLauncherImpl.java @@ -93,8 +93,8 @@ public class ProcessLauncherImpl implements ProcessLauncher { } Process process; - if (command instanceof EsScriptCommand) { - process = launchExternal((EsScriptCommand) command); + if (command instanceof EsScriptCommand esScriptCommand) { + process = launchExternal(esScriptCommand); } else if (command instanceof JavaCommand) { process = launchJava((JavaCommand<?>) command); } else { diff --git a/server/sonar-process/src/main/java/org/sonar/process/PluginFileWriteRule.java b/server/sonar-process/src/main/java/org/sonar/process/PluginFileWriteRule.java index 1008f196d3d..18b055bb1d7 100644 --- a/server/sonar-process/src/main/java/org/sonar/process/PluginFileWriteRule.java +++ b/server/sonar-process/src/main/java/org/sonar/process/PluginFileWriteRule.java @@ -44,11 +44,8 @@ public class PluginFileWriteRule implements PluginPolicyRule { @Override public boolean implies(Permission permission) { - if (permission instanceof FilePermission) { - FilePermission requestPermission = (FilePermission) permission; - if (blockedFilePermission.implies(requestPermission) && !tmpFilePermission.implies(requestPermission)) { - return false; - } + if (permission instanceof FilePermission requestPermission) { + return !blockedFilePermission.implies(requestPermission) || tmpFilePermission.implies(requestPermission); } return true; } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/BaseDoc.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/BaseDoc.java index 847b9df15db..5130fd15655 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/BaseDoc.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/BaseDoc.java @@ -51,12 +51,9 @@ public abstract class BaseDoc { protected BaseDoc(IndexType indexType, Map<String, Object> fields) { this.indexType = indexType; this.fields = fields; - if (indexType instanceof IndexMainType) { - IndexMainType mainType = (IndexMainType) indexType; - if (mainType.getIndex().acceptsRelations()) { - setField(mainType.getIndex().getJoinField(), ImmutableMap.of("name", mainType.getType())); - setField(FIELD_INDEX_TYPE, mainType.getType()); - } + if (indexType instanceof IndexMainType mainType && mainType.getIndex().acceptsRelations()) { + setField(mainType.getIndex().getJoinField(), ImmutableMap.of("name", mainType.getType())); + setField(FIELD_INDEX_TYPE, mainType.getType()); } } @@ -106,11 +103,11 @@ public abstract class BaseDoc { public Date getNullableFieldAsDate(String key) { Object val = getNullableField(key); if (val != null) { - if (val instanceof Date) { - return (Date) val; + if (val instanceof Date date) { + return date; } - if (val instanceof Number) { - return epochSecondsToDate((Number) val); + if (val instanceof Number number) { + return epochSecondsToDate(number); } return EsUtils.parseDateTime((String) val); } @@ -136,11 +133,11 @@ public abstract class BaseDoc { public Date getFieldAsDate(String key) { Object value = getField(key); - if (value instanceof Date) { - return (Date) value; + if (value instanceof Date date) { + return date; } - if (value instanceof Number) { - return epochSecondsToDate((Number) value); + if (value instanceof Number number) { + return epochSecondsToDate(number); } return EsUtils.parseDateTime((String) value); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java index fa073389e66..b2d4f83f761 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/IndexDefinitionHash.java @@ -67,12 +67,12 @@ class IndexDefinitionHash { } private static void appendObject(StringBuilder sb, Object value) { - if (value instanceof Object[]) { - sb.append(Arrays.toString((Object[]) value)); - } else if (value instanceof Map) { - appendMap(sb, (Map) value); - } else if (value instanceof IndexType) { - sb.append(((IndexType) value).format()); + if (value instanceof Object[] arrayValue) { + sb.append(Arrays.toString(arrayValue)); + } else if (value instanceof Map map) { + appendMap(sb, map); + } else if (value instanceof IndexType indexType) { + sb.append(indexType.format()); } else { sb.append(value); } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/es/metadata/MetadataIndexImpl.java b/server/sonar-server-common/src/main/java/org/sonar/server/es/metadata/MetadataIndexImpl.java index 80e91f7e16e..c4377b7ebbf 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/es/metadata/MetadataIndexImpl.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/es/metadata/MetadataIndexImpl.java @@ -68,12 +68,10 @@ public class MetadataIndexImpl implements MetadataIndex { } private static String initializedId(IndexType indexType) { - if (indexType instanceof IndexMainType) { - IndexMainType mainType = (IndexMainType) indexType; + if (indexType instanceof IndexMainType mainType) { return mainType.getIndex().getName() + "." + mainType.getType() + ".initialized"; } - if (indexType instanceof IndexRelationType) { - IndexRelationType relationType = (IndexRelationType) indexType; + if (indexType instanceof IndexRelationType relationType) { IndexMainType mainType = relationType.getMainType(); return mainType.getIndex().getName() + "." + mainType.getType() + "." + relationType.getName() + ".initialized"; } diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java index 488d7efdbce..5afe9794b00 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/FpOrWontFixEmailTemplate.java @@ -54,8 +54,8 @@ public class FpOrWontFixEmailTemplate extends IssueChangesEmailTemplate { .setMessageId(getMessageId(notification.getResolution())) .setSubject(buildSubject(notification)) .setHtmlMessage(buildMessage(notification)); - if (notification.getChange() instanceof UserChange) { - User user = ((UserChange) notification.getChange()).getUser(); + if (notification.getChange() instanceof UserChange userChange) { + User user = userChange.getUser(); emailMessage.setFrom(user.getName().orElse(user.getLogin())); } return emailMessage; diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java index 68fdc0bc6d7..d7c9b93e069 100644 --- a/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java +++ b/server/sonar-server-common/src/main/java/org/sonar/server/issue/notification/IssuesChangesNotificationSerializer.java @@ -222,8 +222,7 @@ public class IssuesChangesNotificationSerializer { private static void serializeChange(IssuesChangesNotification notification, IssuesChangesNotificationBuilder.Change change) { notification.setFieldValue(FIELD_CHANGE_DATE, String.valueOf(change.date)); - if (change instanceof IssuesChangesNotificationBuilder.UserChange) { - IssuesChangesNotificationBuilder.UserChange userChange = (IssuesChangesNotificationBuilder.UserChange) change; + if (change instanceof IssuesChangesNotificationBuilder.UserChange userChange) { User user = userChange.getUser(); notification.setFieldValue(FIELD_CHANGE_AUTHOR_UUID, user.getUuid()); notification.setFieldValue(FIELD_CHANGE_AUTHOR_LOGIN, user.getLogin()); diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/InitFilter.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/InitFilter.java index faa28b4783d..fe35388cc5b 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/InitFilter.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/InitFilter.java @@ -73,11 +73,11 @@ public class InitFilter extends AuthenticationFilter { private void handleProvider(HttpServletRequest request, HttpServletResponse response, IdentityProvider provider) { try { - if (provider instanceof BaseIdentityProvider) { - handleBaseIdentityProvider(request, response, (BaseIdentityProvider) provider); - } else if (provider instanceof OAuth2IdentityProvider) { + if (provider instanceof BaseIdentityProvider baseIdentityProvider) { + handleBaseIdentityProvider(request, response, baseIdentityProvider); + } else if (provider instanceof OAuth2IdentityProvider oAuth2IdentityProvider) { oAuthOAuth2AuthenticationParameters.init(request, response); - handleOAuth2IdentityProvider(request, response, (OAuth2IdentityProvider) provider); + handleOAuth2IdentityProvider(request, response, oAuth2IdentityProvider); } else { handleError(request, response, format("Unsupported IdentityProvider class: %s", provider.getClass())); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/OAuth2CallbackFilter.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/OAuth2CallbackFilter.java index 389436e5636..c3b5a664073 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/OAuth2CallbackFilter.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/OAuth2CallbackFilter.java @@ -71,8 +71,8 @@ public class OAuth2CallbackFilter extends AuthenticationFilter { private void handleProvider(HttpServletRequest request, HttpServletResponse response, IdentityProvider provider) { try { - if (provider instanceof OAuth2IdentityProvider) { - handleOAuth2Provider(response, request, (OAuth2IdentityProvider) provider); + if (provider instanceof OAuth2IdentityProvider oAuth2IdentityProvider) { + handleOAuth2Provider(response, request, oAuth2IdentityProvider); } else { handleError(request, response, format("Not an OAuth2IdentityProvider: %s", provider.getClass())); } diff --git a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java index 66376c77170..fa6be146e7e 100644 --- a/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java +++ b/server/sonar-webserver-auth/src/main/java/org/sonar/server/authentication/UserSessionInitializer.java @@ -141,8 +141,8 @@ public class UserSessionInitializer { } private static void checkTokenUserSession(HttpServletResponse response, UserSession session) { - if (session instanceof TokenUserSession) { - UserTokenDto userTokenDto = ((TokenUserSession) session).getUserToken(); + if (session instanceof TokenUserSession tokenUserSession) { + UserTokenDto userTokenDto = tokenUserSession.getUserToken(); Optional.ofNullable(userTokenDto.getExpirationDate()).ifPresent(expirationDate -> response.addHeader(SQ_AUTHENTICATION_TOKEN_EXPIRATION, formatDateTime(expirationDate))); } } diff --git a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/web/RootFilter.java b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/web/RootFilter.java index dfe49682045..4803903e9f9 100644 --- a/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/web/RootFilter.java +++ b/server/sonar-webserver-core/src/main/java/org/sonar/server/platform/web/RootFilter.java @@ -58,8 +58,7 @@ public class RootFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { - if (request instanceof HttpServletRequest) { - HttpServletRequest httpRequest = (HttpServletRequest) request; + if (request instanceof HttpServletRequest httpRequest) { HttpServletResponse httpResponse = (HttpServletResponse) response; try { chain.doFilter(new ServletRequestWrapper(httpRequest), httpResponse); diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectAction.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectAction.java index 28edcefa656..bb125f8b175 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectAction.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/batch/ProjectAction.java @@ -103,8 +103,8 @@ public class ProjectAction implements BatchWsAction { private static WsProjectResponse buildResponse(ProjectRepositories data) { WsProjectResponse.Builder response = WsProjectResponse.newBuilder(); - if (data instanceof SingleProjectRepository) { - response.putAllFileDataByPath(buildFileDataByPath((SingleProjectRepository) data)); + if (data instanceof SingleProjectRepository singleProjectRepository) { + response.putAllFileDataByPath(buildFileDataByPath(singleProjectRepository)); } else { response.putAllFileDataByModuleAndPath(buildFileDataByModuleAndPath((MultiModuleProjectRepository) data)); } diff --git a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java index d6ab624c000..f3bdf455d6b 100644 --- a/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java +++ b/server/sonar-webserver-webapi/src/main/java/org/sonar/server/permission/PermissionUpdater.java @@ -55,11 +55,11 @@ public class PermissionUpdater { } private boolean doApply(DbSession dbSession, PermissionChange change) { - if (change instanceof UserPermissionChange) { - return userPermissionChanger.apply(dbSession, (UserPermissionChange) change); + if (change instanceof UserPermissionChange userPermissionChange) { + return userPermissionChanger.apply(dbSession, userPermissionChange); } - if (change instanceof GroupPermissionChange) { - return groupPermissionChanger.apply(dbSession, (GroupPermissionChange) change); + if (change instanceof GroupPermissionChange groupPermissionChange) { + return groupPermissionChanger.apply(dbSession, groupPermissionChange); } throw new UnsupportedOperationException("Unsupported permission change: " + change.getClass()); diff --git a/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java b/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java index 4c9d380cd2f..da04ef94fdd 100644 --- a/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java +++ b/server/sonar-webserver-ws/src/main/java/org/sonar/server/ws/WebServiceEngine.java @@ -102,9 +102,9 @@ public class WebServiceEngine implements LocalConnector, Startable { ActionExtractor actionExtractor = new ActionExtractor(request.getPath()); WebService.Action action = getAction(actionExtractor); checkFound(action, "Unknown url : %s", request.getPath()); - if (request instanceof ValidatingRequest) { - ((ValidatingRequest) request).setAction(action); - ((ValidatingRequest) request).setLocalConnector(this); + if (request instanceof ValidatingRequest validatingRequest) { + validatingRequest.setAction(action); + validatingRequest.setLocalConnector(this); } checkActionExtension(actionExtractor.getExtension()); verifyRequest(action, request); @@ -160,8 +160,8 @@ public class WebServiceEngine implements LocalConnector, Startable { } // response is not committed, status and content can be changed to return the error - if (stream instanceof ServletResponse.ServletStream) { - ((ServletResponse.ServletStream) stream).reset(); + if (stream instanceof ServletResponse.ServletStream servletStream) { + servletStream.reset(); } stream.setStatus(status); stream.setMediaType(MediaTypes.JSON); @@ -189,7 +189,7 @@ public class WebServiceEngine implements LocalConnector, Startable { private static boolean isResponseCommitted(Response response) { Response.Stream stream = response.stream(); // Request has been aborted by the client or the response was partially streamed, nothing can been done as Tomcat has committed the response - return stream instanceof ServletResponse.ServletStream && ((ServletResponse.ServletStream) stream).response().isCommitted(); + return stream instanceof ServletResponse.ServletStream servletStream && servletStream.response().isCommitted(); } public static void writeErrors(JsonWriter json, List<String> errorMessages) { |