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
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment
// Skip all not-public elements
checkPublicVisibility(null, element);

if (element instanceof TypeElement) {
process((TypeElement) element);
if (element instanceof TypeElement typeElement) {
process(typeElement);
}
}

Expand Down Expand Up @@ -185,31 +185,31 @@ private void process(ExecutableElement executable, Element enclosing) {

// Process method return types
final TypeMirror returnType = executable.getReturnType();
if (returnType instanceof ReferenceType) {
process(executable, (ReferenceType) returnType);
if (returnType instanceof ReferenceType refType) {
process(executable, refType);
}

// Process method thrown types
for (final TypeMirror thrownType : executable.getThrownTypes()) {
if (thrownType instanceof ReferenceType) {
process(executable, (ReferenceType) thrownType);
if (thrownType instanceof ReferenceType refType) {
process(executable, refType);
}
}

// Process method type parameters
for (final TypeParameterElement typeParameter : executable.getTypeParameters()) {
for (final TypeMirror boundType : typeParameter.getBounds()) {
if (boundType instanceof ReferenceType) {
process(executable, (ReferenceType) boundType);
if (boundType instanceof ReferenceType refType) {
process(executable, refType);
}
}
}

// Process method arguments
for (final VariableElement parameter : executable.getParameters()) {
final TypeMirror parameterType = parameter.asType();
if (parameterType instanceof ReferenceType) {
process(executable, (ReferenceType) parameterType);
if (parameterType instanceof ReferenceType refType) {
process(executable, refType);
}
}
}
Expand All @@ -220,12 +220,12 @@ private void process(ExecutableElement executable, Element enclosing) {
* @param type wildcard type
*/
private void process(ExecutableElement executable, WildcardType type) {
if (type.getExtendsBound() instanceof ReferenceType) {
process(executable, (ReferenceType) type.getExtendsBound());
if (type.getExtendsBound() instanceof ReferenceType refType) {
process(executable, refType);
}

if (type.getSuperBound() instanceof ReferenceType) {
process(executable, (ReferenceType) type.getSuperBound());
if (type.getSuperBound() instanceof ReferenceType refType) {
process(executable, refType);
}
}

Expand All @@ -240,8 +240,7 @@ private void process(ExecutableElement executable, ReferenceType ref) {
return;
}

if (ref instanceof DeclaredType) {
final DeclaredType declaredType = (DeclaredType) ref;
if (ref instanceof DeclaredType declaredType) {

final Element element = declaredType.asElement();
if (inspectable(element)) {
Expand All @@ -250,24 +249,23 @@ private void process(ExecutableElement executable, ReferenceType ref) {
}

for (final TypeMirror type : declaredType.getTypeArguments()) {
if (type instanceof ReferenceType) {
process(executable, (ReferenceType) type);
} else if (type instanceof WildcardType) {
process(executable, (WildcardType) type);
if (type instanceof ReferenceType refType) {
process(executable, refType);
} else if (type instanceof WildcardType wildcardType) {
process(executable, wildcardType);
}
}
} else if (ref instanceof ArrayType) {
final TypeMirror componentType = ((ArrayType) ref).getComponentType();
if (componentType instanceof ReferenceType) {
process(executable, (ReferenceType) componentType);
} else if (ref instanceof ArrayType arrayType) {
final TypeMirror componentType = arrayType.getComponentType();
if (componentType instanceof ReferenceType refType) {
process(executable, refType);
}
} else if (ref instanceof TypeVariable) {
final TypeVariable typeVariable = (TypeVariable) ref;
if (typeVariable.getUpperBound() instanceof ReferenceType) {
process(executable, (ReferenceType) typeVariable.getUpperBound());
} else if (ref instanceof TypeVariable typeVariable) {
if (typeVariable.getUpperBound() instanceof ReferenceType refType) {
process(executable, refType);
}
if (typeVariable.getLowerBound() instanceof ReferenceType) {
process(executable, (ReferenceType) typeVariable.getLowerBound());
if (typeVariable.getLowerBound() instanceof ReferenceType refType) {
process(executable, refType);
}
}

Expand Down Expand Up @@ -348,8 +346,8 @@ private void process(Element element) {
continue;
}

if (enclosed instanceof ExecutableElement) {
process((ExecutableElement) enclosed, element);
if (enclosed instanceof ExecutableElement executableElement) {
process(executableElement, element);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public static void checkJarHell(Consumer<String> output) throws IOException, URI
ClassLoader loader = JarHell.class.getClassLoader();
output.accept("java.class.path: " + System.getProperty("java.class.path"));
output.accept("sun.boot.class.path: " + System.getProperty("sun.boot.class.path"));
if (loader instanceof URLClassLoader) {
output.accept("classloader urls: " + Arrays.toString(((URLClassLoader) loader).getURLs()));
if (loader instanceof URLClassLoader urlClassLoader) {
output.accept("classloader urls: " + Arrays.toString(urlClassLoader.getURLs()));
}
checkJarHell(parseClassPath(), output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@
public class NetworkExceptionHelper {

public static boolean isConnectException(Throwable e) {
if (e instanceof ConnectException) {
return true;
}
return false;
return e instanceof ConnectException;
}

public static boolean isCloseConnectionException(Throwable e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public static void close(final Exception ex, final Iterable<? extends Closeable>
}

if (firstException != null) {
if (firstException instanceof IOException) {
throw (IOException) firstException;
if (firstException instanceof IOException ioe) {
throw ioe;
} else {
// since we only assigned an IOException or a RuntimeException to ex above, in this case ex must be a RuntimeException
throw (RuntimeException) firstException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static <T> HashSet<T> newHashSet(Iterator<T> iterator) {

public static <T> HashSet<T> newHashSet(Iterable<T> iterable) {
Objects.requireNonNull(iterable);
return iterable instanceof Collection ? new HashSet<>((Collection) iterable) : newHashSet(iterable.iterator());
return iterable instanceof Collection<T> collection ? new HashSet<>(collection) : newHashSet(iterable.iterator());
}

public static <T> HashSet<T> newHashSet(T... elements) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,8 @@ public static Throwable unwrap(Throwable t, Class<?>... clazzes) {
*/
public static boolean reThrowIfNotNull(@Nullable Throwable e) {
if (e != null) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
if (e instanceof RuntimeException re) {
throw re;
} else {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -442,8 +442,8 @@ private static class GroupBy {
// which does not include the cluster alias.
String indexName = failure.index();
if (indexName == null) {
if (cause instanceof OpenSearchException) {
final Index index = ((OpenSearchException) cause).getIndex();
if (cause instanceof OpenSearchException ose) {
final Index index = ose.getIndex();
if (index != null) {
indexName = index.getName();
}
Expand Down
19 changes: 9 additions & 10 deletions libs/core/src/main/java/org/opensearch/OpenSearchException.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ public String getDetailedMessage() {
if (getCause() != null) {
StringBuilder sb = new StringBuilder();
sb.append(toString()).append("; ");
if (getCause() instanceof OpenSearchException) {
sb.append(((OpenSearchException) getCause()).getDetailedMessage());
if (getCause() instanceof OpenSearchException ose) {
sb.append(ose.getDetailedMessage());
} else {
sb.append(getCause());
}
Expand Down Expand Up @@ -409,8 +409,7 @@ protected static void innerToXContent(
headerToXContent(builder, entry.getKey().substring(OPENSEARCH_PREFIX_KEY.length()), entry.getValue());
}

if (throwable instanceof OpenSearchException) {
OpenSearchException exception = (OpenSearchException) throwable;
if (throwable instanceof OpenSearchException exception) {
exception.metadataToXContent(builder, params);
}

Expand Down Expand Up @@ -602,8 +601,8 @@ public static OpenSearchException innerFromXContent(XContentParser parser, boole
public static void generateThrowableXContent(XContentBuilder builder, ToXContent.Params params, Throwable t) throws IOException {
t = ExceptionsHelper.unwrapCause(t);

if (t instanceof OpenSearchException) {
((OpenSearchException) t).toXContent(builder, params);
if (t instanceof OpenSearchException ose) {
ose.toXContent(builder, params);
} else {
innerToXContent(builder, params, t, getExceptionName(t), t.getMessage(), emptyMap(), emptyMap(), t.getCause());
}
Expand Down Expand Up @@ -674,8 +673,8 @@ public static OpenSearchException failureFromXContent(XContentParser parser) thr
*/
public OpenSearchException[] guessRootCauses() {
final Throwable cause = getCause();
if (cause != null && cause instanceof OpenSearchException) {
return ((OpenSearchException) cause).guessRootCauses();
if (cause instanceof OpenSearchException ose) {
return ose.guessRootCauses();
}
return new OpenSearchException[] { this };
}
Expand All @@ -687,9 +686,9 @@ public OpenSearchException[] guessRootCauses() {
*/
public static OpenSearchException[] guessRootCauses(Throwable t) {
Throwable ex = ExceptionsHelper.unwrapCause(t);
if (ex instanceof OpenSearchException) {
if (ex instanceof OpenSearchException ose) {
// OpenSearchException knows how to guess its own root cause
return ((OpenSearchException) ex).guessRootCauses();
return ose.guessRootCauses();
}
if (ex instanceof XContentParseException) {
/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other instanceof BytesReference) {
final BytesReference otherRef = (BytesReference) other;
if (other instanceof BytesReference otherRef) {
if (length() != otherRef.length()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other instanceof BytesArray) {
final BytesArray that = (BytesArray) other;
if (other instanceof BytesArray that) {
return Arrays.equals(bytes, offset, offset + length, that.bytes, that.offset, that.offset + that.length);
}
return super.equals(other);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public void reset() throws IOException {

@Override
public void close() throws IOException {
if (out instanceof Closeable) {
((Closeable) out).close();
if (out instanceof Closeable closeable) {
closeable.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ public NotSerializableExceptionWrapper(Throwable other) {
for (Throwable otherSuppressed : other.getSuppressed()) {
addSuppressed(otherSuppressed);
}
if (other instanceof OpenSearchException) {
OpenSearchException ex = (OpenSearchException) other;
if (other instanceof OpenSearchException ex) {
for (String key : ex.getHeaderKeys()) {
this.addHeader(key, ex.getHeader(key));
}
Expand Down
Loading
Loading