@@ -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"); |
@@ -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"); | |||
} |
@@ -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()); | |||
} |
@@ -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()); |
@@ -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); | |||
} |
@@ -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()); | |||
} | |||
} | |||
@@ -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 { |
@@ -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; | |||
} |
@@ -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); | |||
} |
@@ -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); | |||
} |
@@ -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"; | |||
} |
@@ -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; |
@@ -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()); |
@@ -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())); | |||
} |
@@ -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())); | |||
} |
@@ -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))); | |||
} | |||
} |
@@ -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); |
@@ -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)); | |||
} |
@@ -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()); | |||
@@ -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) { |