Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.
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 @@ -307,8 +307,7 @@ public Injector initialize()
Map<String, ConfigurationDefaultingModule> moduleDefaultSource = new HashMap<>();
List<Message> moduleDefaultErrors = new ArrayList<>();
for (Module module : modules) {
if (module instanceof ConfigurationDefaultingModule) {
ConfigurationDefaultingModule configurationDefaultingModule = (ConfigurationDefaultingModule) module;
if (module instanceof ConfigurationDefaultingModule configurationDefaultingModule) {
Map<String, String> defaults = configurationDefaultingModule.getConfigurationDefaults();
for (Entry<String, String> entry : defaults.entrySet()) {
ConfigurationDefaultingModule oldModule = moduleDefaultSource.put(entry.getKey(), configurationDefaultingModule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@ public static <V> CompletableFuture<V> firstCompletedFuture(Iterable<? extends C
future.exceptionally(throwable -> {
if (throwable instanceof CancellationException) {
for (CompletionStage<? extends V> sourceFuture : futures) {
if (sourceFuture instanceof Future) {
((Future<?>) sourceFuture).cancel(true);
if (sourceFuture instanceof Future<?> f) {
f.cancel(true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ protected synchronized <T> T buildConfigObject(Class<T> configClass, String pref

protected synchronized void install(Module module)
{
if (module instanceof ConfigurationAwareModule) {
((ConfigurationAwareModule) module).setConfigurationFactory(configurationFactory);
if (module instanceof ConfigurationAwareModule configurationAwareModule) {
configurationAwareModule.setConfigurationFactory(configurationFactory);
}
binder.install(module);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,9 @@ public List<Message> validate(Iterable<? extends Module> modules)
public <T> Void visit(Binding<T> binding)
{
// look for ConfigurationAwareProviders...
if (binding instanceof ProviderInstanceBinding) {
ProviderInstanceBinding<?> providerInstanceBinding = (ProviderInstanceBinding<?>) binding;
if (binding instanceof ProviderInstanceBinding<?> providerInstanceBinding) {
Provider<?> provider = providerInstanceBinding.getUserSuppliedProvider();
if (provider instanceof ConfigurationAwareProvider) {
ConfigurationAwareProvider<?> configurationProvider = (ConfigurationAwareProvider<?>) provider;
if (provider instanceof ConfigurationAwareProvider<?> configurationProvider) {
// give the provider the configuration factory
configurationProvider.setConfigurationFactory(configurationFactory);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ private TypeParameterUtils()

public static Type[] getTypeParameters(Class<?> desiredType, Type type)
{
if (type instanceof Class) {
Class<?> rawClass = (Class<?>) type;

if (type instanceof Class<?> rawClass) {
// if this is the collection class we're done
if (desiredType.equals(type)) {
return null;
Expand All @@ -46,9 +44,7 @@ public static Type[] getTypeParameters(Class<?> desiredType, Type type)

return getTypeParameters(desiredType, rawClass.getGenericSuperclass());
}
if (type instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) type;

if (type instanceof ParameterizedType parameterizedType) {
Type rawType = parameterizedType.getRawType();
if (desiredType.equals(rawType)) {
return parameterizedType.getActualTypeArguments();
Expand All @@ -57,8 +53,7 @@ public static Type[] getTypeParameters(Class<?> desiredType, Type type)
Type[] collectionTypes = getTypeParameters(desiredType, rawType);
if (collectionTypes != null) {
for (int i = 0; i < collectionTypes.length; i++) {
if (collectionTypes[i] instanceof TypeVariable) {
TypeVariable<?> typeVariable = (TypeVariable<?>) collectionTypes[i];
if (collectionTypes[i] instanceof TypeVariable<?> typeVariable) {
TypeVariable<?>[] rawTypeParams = ((GenericDeclaration) rawType).getTypeParameters();
for (int j = 0; j < rawTypeParams.length; j++) {
if (typeVariable.getName().equals(rawTypeParams[j].getName())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,8 @@ public final T handleException(Request request, Exception exception)
if (exception instanceof CancellationException) {
throw new DiscoveryException(name + " was canceled");
}
if (exception instanceof DiscoveryException) {
throw (DiscoveryException) exception;
if (exception instanceof DiscoveryException discoveryException) {
throw discoveryException;
}

throw new DiscoveryException(name + " failed", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ public boolean equals(Object o)
if (this == o) {
return true;
}
if (!(o instanceof ServiceType)) {
if (!(o instanceof ServiceType that)) {
return false;
}

ServiceType that = (ServiceType) o;

if (!value.equals(that.value())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public final T handleException(Request request, Exception exception)
if (exception instanceof CancellationException) {
throw new DiscoveryException(name + " was canceled");
}
if (exception instanceof DiscoveryException) {
throw (DiscoveryException) exception;
if (exception instanceof DiscoveryException discoveryException) {
throw discoveryException;
}

throw new DiscoveryException(name + " failed", exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,15 @@ private Class<?> extractIterableType(Method method)
return null;
}
Type type = types[0];
if (!(type instanceof Class)) {
if (!(type instanceof Class<?> clazz)) {
addMethodError("Iterable type parameter [%s] must be an exact type", method, type);
return null;
}
if (isIterable((Class<?>) type)) {
if (isIterable(clazz)) {
addMethodError("Iterable of iterable is not supported", method);
return null;
}
return (Class<?>) type;
return clazz;
}

private Class<?> extractMapType(Method method, Class<?> mapClass)
Expand All @@ -258,22 +258,22 @@ private Class<?> extractMapType(Method method, Class<?> mapClass)
}
Type keyType = types[0];
Type valueType = types[1];
if (!(keyType instanceof Class)) {
if (!(keyType instanceof Class<?> keyClass)) {
addMethodError("%s key type parameter [%s] must be an exact type", method, className, keyType);
return null;
}
if (!(valueType instanceof Class)) {
if (!(valueType instanceof Class<?> valueClass)) {
addMethodError("%s value type parameter [%s] must be an exact type", method, className, valueType);
return null;
}
if (!isString((Class<?>) keyType)) {
if (!isString(keyClass)) {
addMethodError("%s key type parameter [%s] must be a String", method, className, keyType);
}
if (isIterable((Class<?>) valueType)) {
if (isIterable(valueClass)) {
addMethodError("%s value type parameter [%s] cannot be iterable", method, className, valueType);
return null;
}
return (Class<?>) valueType;
return valueClass;
}

@SuppressWarnings("unchecked")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,9 @@ public int hashCode()
@Override
public boolean equals(Object obj)
{
if (!(obj instanceof Request)) {
if (!(obj instanceof Request r)) {
return false;
}
final Request r = (Request) obj;
return Objects.equals(uri, r.uri) &&
Objects.equals(method, r.method) &&
Objects.equals(headers, r.headers) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ private ResponseHandlerUtils()
@SuppressWarnings("deprecation")
public static RuntimeException propagate(Request request, Throwable exception)
{
if (exception instanceof ConnectException) {
throw new UncheckedIOException("Server refused connection: " + request.getUri().toASCIIString(), (ConnectException) exception);
if (exception instanceof ConnectException connectException) {
throw new UncheckedIOException("Server refused connection: " + request.getUri().toASCIIString(), connectException);
}
if (exception instanceof IOException) {
throw new UncheckedIOException((IOException) exception);
if (exception instanceof IOException ioException) {
throw new UncheckedIOException(ioException);
}
throwIfUnchecked(exception);
throw new RuntimeException(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,10 @@ public boolean equals(Object o)
if (this == o) {
return true;
}
if (!(o instanceof ServiceType)) {
if (!(o instanceof ServiceType that)) {
return false;
}

ServiceType that = (ServiceType) o;

if (!value.equals(that.value())) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,17 +228,17 @@ RetryBudget getRetryBudget() {
@Managed
public String dump()
{
if (httpClient instanceof JettyHttpClient) {
return ((JettyHttpClient) httpClient).dump();
if (httpClient instanceof JettyHttpClient jettyHttpClient) {
return jettyHttpClient.dump();
}
return null;
}

@Managed
public void dumpStdErr()
{
if (httpClient instanceof JettyHttpClient) {
((JettyHttpClient) httpClient).dumpStdErr();
if (httpClient instanceof JettyHttpClient jettyHttpClient) {
jettyHttpClient.dumpStdErr();
}
}

Expand Down Expand Up @@ -303,18 +303,17 @@ public void onSuccess(T result)
@Override
public void onFailure(Throwable t)
{
if (t instanceof InnerHandlerException) {
InnerHandlerException innerHandlerException = (InnerHandlerException) t;
if (t instanceof InnerHandlerException innerHandlerException) {
attempt.markBad(innerHandlerException.getFailureCategory(), innerHandlerException.getHandlerCategory());
setException(t.getCause());
setException(innerHandlerException.getCause());
}
else if (t instanceof FailureStatusException) {
attempt.markBad(((FailureStatusException) t).getFailureCategory());
else if (t instanceof FailureStatusException failureStatusException) {
attempt.markBad(failureStatusException.getFailureCategory());
//noinspection unchecked
set((T) ((FailureStatusException) t).result);
set((T) failureStatusException.result);
}
else if (t instanceof RetryException) {
attempt.markBad(((RetryException) t).getFailureCategory());
else if (t instanceof RetryException retryException) {
attempt.markBad(retryException.getFailureCategory());
TraceToken traceToken = getCurrentTraceToken();
synchronized (subFutureLock) {
Duration backoff = attemptBackoffPolicy.backoff(previousBackoff);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ public T handle(Request request, Response response)
private static boolean bodySourceRetryable(Request request)
{
BodySource bodySource = request.getBodySource();
return !(bodySource instanceof LimitedRetryable) || ((LimitedRetryable) bodySource).isRetryable();
return !(bodySource instanceof LimitedRetryable limitedRetryable) || limitedRetryable.isRetryable();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ private void close()
try (AutoLock ignored = lock.lock()) {
closed = true;
}
if (writer instanceof AutoCloseable) {
if (writer instanceof AutoCloseable closeableWriter) {
try (TraceTokenScope ignored = registerTraceToken(traceToken)) {
((AutoCloseable) writer).close();
closeableWriter.close();
}
catch (Throwable x) {
try (AutoLock ignored = lock.lock()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ public void onContent(Response response, ByteBuffer content)
if (cause instanceof RejectedExecutionException || cause instanceof ClosedByInterruptException) {
maybeLogJettyState();
}
if (cause instanceof Exception) {
return responseHandler.handleException(request, (Exception) cause);
if (cause instanceof Exception x) {
return responseHandler.handleException(request, x);
}
return responseHandler.handleException(request, new RuntimeException(cause));
}
Expand Down Expand Up @@ -517,16 +517,15 @@ private HttpRequest buildJettyRequest(Request finalRequest, AtomicLong bytesWrit

BodySource bodySource = finalRequest.getBodySource();
if (bodySource != null) {
if (bodySource instanceof StaticBodyGenerator) {
StaticBodyGenerator staticBodyGenerator = (StaticBodyGenerator) bodySource;
if (bodySource instanceof StaticBodyGenerator staticBodyGenerator) {
jettyRequest.body(new BytesRequestContent(staticBodyGenerator.getBody()));
bytesWritten.addAndGet(staticBodyGenerator.getBody().length);
}
else if (bodySource instanceof InputStreamBodySource) {
jettyRequest.body(new InputStreamBodySourceContentProvider((InputStreamBodySource) bodySource, bytesWritten));
else if (bodySource instanceof InputStreamBodySource inputStreamBodySource) {
jettyRequest.body(new InputStreamBodySourceContentProvider(inputStreamBodySource, bytesWritten));
}
else if (bodySource instanceof DynamicBodySource) {
jettyRequest.body(new DynamicBodySourceContentProvider((DynamicBodySource) bodySource, bytesWritten));
else if (bodySource instanceof DynamicBodySource dynamicBodySource) {
jettyRequest.body(new DynamicBodySourceContentProvider(dynamicBodySource, bytesWritten));
}
else {
throw new IllegalArgumentException("Request has unsupported BodySource type");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ void failed(Throwable throwable)
}
try (TraceTokenScope ignored = registerTraceToken(traceToken)) {
// give handler a chance to rewrite the exception or return a value instead
if (throwable instanceof Exception) {
if (throwable instanceof Exception x) {
try {
if (throwable instanceof RejectedExecutionException) {
if (x instanceof RejectedExecutionException) {
jettyHttpClient.maybeLogJettyState();
}
T value = responseHandler.handleException(request, (Exception) throwable);
T value = responseHandler.handleException(request, x);
// handler returned a value, store it in the future
state.set(JettyAsyncHttpState.DONE);
set(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ private BodySourceTester()
public static void writeBodySourceTo(BodySource bodySource, final OutputStream out)
throws Exception
{
if (bodySource instanceof StaticBodyGenerator) {
out.write(((StaticBodyGenerator) bodySource).getBody());
if (bodySource instanceof StaticBodyGenerator staticBodyGenerator) {
out.write(staticBodyGenerator.getBody());
}
else if (bodySource instanceof InputStreamBodySource) {
InputStream in = ((InputStreamBodySource) bodySource).getInputStream();
byte[] buf = new byte[((InputStreamBodySource) bodySource).getBufferSize()];
else if (bodySource instanceof InputStreamBodySource inputStreamBodySource) {
InputStream in = inputStreamBodySource.getInputStream();
byte[] buf = new byte[inputStreamBodySource.getBufferSize()];
while (true) {
int r = in.read(buf);
if (r == -1) {
Expand All @@ -34,9 +34,9 @@ else if (bodySource instanceof InputStreamBodySource) {
out.write(buf, 0, r);
}
}
else if (bodySource instanceof DynamicBodySource) {
else if (bodySource instanceof DynamicBodySource dynamicBodySource) {
final AtomicBoolean closed = new AtomicBoolean(false);
Writer writer = ((DynamicBodySource) bodySource).start(new OutputStream()
Writer writer = dynamicBodySource.start(new OutputStream()
{
@Override
public void write(int b)
Expand Down Expand Up @@ -77,8 +77,8 @@ public void close()
writer.write();
}

if (writer instanceof AutoCloseable) {
((AutoCloseable) writer).close();
if (writer instanceof AutoCloseable closeable) {
closeable.close();
}
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ private <T, E extends Exception> T execute(Request request, ResponseHandler<T, E
state.set("FAILED");
long responseStart = System.nanoTime();
Duration requestProcessingTime = new Duration(responseStart - requestStart, TimeUnit.NANOSECONDS);
if (e instanceof Exception) {
if (e instanceof Exception x) {
if (e instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
try {
return responseHandler.handleException(request, (Exception) e);
return responseHandler.handleException(request, x);
}
finally {
stats.record(request.getMethod(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,9 @@ public void write(int b)

Object response = responses.remove(0);
// TODO: defer availability of return values ?
if (response instanceof Exception) {
if (response instanceof Exception x) {
try {
return new ImmediateAsyncHttpFuture<>(responseHandler.handleException(request, (Exception) response));
return new ImmediateAsyncHttpFuture<>(responseHandler.handleException(request, x));
}
catch (Exception e) {
return new ImmediateFailedAsyncHttpFuture<>((E) e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ public void write(int b)
}

Object response = responses.remove(0);
if (response instanceof Exception) {
return responseHandler.handleException(request, (Exception) response);
if (response instanceof Exception x) {
return responseHandler.handleException(request, x);
}
return responseHandler.handle(request, (Response) response);
}
Expand Down
Loading