@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");
@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");
}
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());
}
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());
}
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);
}
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);
}
if (stacktrace != null) {
activityDto.setErrorStacktrace(stacktrace);
}
- if (error instanceof TypedException) {
- activityDto.setErrorType(((TypedException) error).getType());
+ if (error instanceof TypedException typedException) {
+ activityDto.setErrorType(typedException.getType());
}
}
}
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 {
@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;
}
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());
}
}
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);
}
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);
}
}
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);
}
}
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";
}
.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;
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());
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()));
}
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()));
}
}
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)));
}
}
@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);
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));
}
}
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());
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);
}
// 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);
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) {