Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions server/src/main/java/org/opensearch/action/ActionModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -847,11 +847,11 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
List<AbstractCatAction> catActions = new ArrayList<>();
List<AbstractListAction> listActions = new ArrayList<>();
Consumer<RestHandler> registerHandler = handler -> {
if (handler instanceof AbstractCatAction) {
if (handler instanceof AbstractListAction && ((AbstractListAction) handler).isActionPaginated()) {
listActions.add((AbstractListAction) handler);
if (handler instanceof AbstractCatAction abstractCatAction) {
if (handler instanceof AbstractListAction abstractListAction && abstractListAction.isActionPaginated()) {
listActions.add(abstractListAction);
} else {
catActions.add((AbstractCatAction) handler);
catActions.add(abstractCatAction);
}
}
restController.registerHandler(handler);
Expand Down Expand Up @@ -1265,8 +1265,8 @@ public void unregisterDynamicRoute(NamedRoute route) {
* @return the corresponding {@link RestSendToExtensionAction} if it is registered, null otherwise.
*/
public RestSendToExtensionAction get(RestHandler.Route route) {
if (route instanceof NamedRoute) {
return routeRegistry.get((NamedRoute) route);
if (route instanceof NamedRoute namedRoute) {
return routeRegistry.get(namedRoute);
}
// Only NamedRoutes are map keys so any other route is not in the map
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public TransportRequestOptions transportOptions(Settings settings) {

@Override
public boolean equals(Object o) {
return o instanceof ActionType && name.equals(((ActionType<?>) o).name());
return o instanceof ActionType<?> actionType && name.equals(actionType.name());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,9 @@ public TransportBulkAction(
*/
public static IndexRequest getIndexWriteRequest(DocWriteRequest<?> docWriteRequest) {
IndexRequest indexRequest = null;
if (docWriteRequest instanceof IndexRequest) {
indexRequest = (IndexRequest) docWriteRequest;
} else if (docWriteRequest instanceof UpdateRequest) {
UpdateRequest updateRequest = (UpdateRequest) docWriteRequest;
if (docWriteRequest instanceof IndexRequest indexReq) {
indexRequest = indexReq;
} else if (docWriteRequest instanceof UpdateRequest updateRequest) {
indexRequest = updateRequest.docAsUpsert() ? updateRequest.doc() : updateRequest.upsertRequest();
}
return indexRequest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ public void printStackTrace(PrintWriter s) {
private void printStackTrace(Consumer<String> consumer) {
Throwable originalCause = getCause();
Throwable cause = originalCause;
if (cause instanceof CreationException) {
cause = getFirstGuiceCause((CreationException) cause);
if (cause instanceof CreationException creationException) {
cause = getFirstGuiceCause(creationException);
}

if (cause != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,8 +569,7 @@ public void onFailure(Exception e) {

@Override
public void onRejection(Exception e) {
final boolean shutDown = e instanceof OpenSearchRejectedExecutionException
&& ((OpenSearchRejectedExecutionException) e).isExecutorShutdown();
final boolean shutDown = e instanceof OpenSearchRejectedExecutionException osre && osre.isExecutorShutdown();
logger.log(shutDown ? Level.DEBUG : Level.WARN, "refreshing cluster info rejected [{}]", reason, e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -352,15 +352,12 @@ public void exposedButNotBound(Key<?> key) {
}

public static Collection<Message> getMessagesFromThrowable(Throwable throwable) {
if (throwable instanceof ProvisionException) {
return ((ProvisionException) throwable).getErrorMessages();
} else if (throwable instanceof ConfigurationException) {
return ((ConfigurationException) throwable).getErrorMessages();
} else if (throwable instanceof CreationException) {
return ((CreationException) throwable).getErrorMessages();
} else {
return emptySet();
}
return switch (throwable) {
case ProvisionException provisionException -> provisionException.getErrorMessages();
case ConfigurationException configurationException -> configurationException.getErrorMessages();
case CreationException creationException -> creationException.getErrorMessages();
default -> emptySet();
};
}

public Errors errorInUserCode(Throwable cause, String messageFormat, Object... arguments) {
Expand Down Expand Up @@ -649,29 +646,27 @@ public static Object convert(Object o) {
}

public static void formatSource(Formatter formatter, Object source) {
if (source instanceof Dependency) {
Dependency<?> dependency = (Dependency<?>) source;
if (source instanceof Dependency<?> dependency) {
InjectionPoint injectionPoint = dependency.getInjectionPoint();
if (injectionPoint != null) {
formatInjectionPoint(formatter, dependency, injectionPoint);
} else {
formatSource(formatter, dependency.getKey());
}

} else if (source instanceof InjectionPoint) {
formatInjectionPoint(formatter, null, (InjectionPoint) source);
} else if (source instanceof InjectionPoint injectionPoint) {
formatInjectionPoint(formatter, null, injectionPoint);

} else if (source instanceof Class) {
formatter.format(" at %s%n", StackTraceElements.forType((Class<?>) source));
} else if (source instanceof Class<?> clazz) {
formatter.format(" at %s%n", StackTraceElements.forType(clazz));

} else if (source instanceof Member) {
formatter.format(" at %s%n", StackTraceElements.forMember((Member) source));
} else if (source instanceof Member member) {
formatter.format(" at %s%n", StackTraceElements.forMember(member));

} else if (source instanceof TypeLiteral) {
formatter.format(" while locating %s%n", source);

} else if (source instanceof Key) {
Key<?> key = (Key<?>) source;
} else if (source instanceof Key<?> key) {
formatter.format(" while locating %s%n", convert(key));

} else {
Expand Down
Loading
Loading