From 162c09d0365a9bf83874effa0b5ac2205d0c3168 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 5 Mar 2023 16:03:50 +0100 Subject: [PATCH] Apply "instanceof pattern matching" in remainder of spring-context-support module See gh-30067 --- .../springframework/cache/caffeine/CaffeineCache.java | 6 +++--- .../jcache/config/AbstractJCacheConfiguration.java | 6 +++--- .../cache/jcache/config/package-info.java | 10 +++++----- .../interceptor/DefaultCacheKeyInvocationContext.java | 6 +++--- .../scheduling/quartz/AdaptableJobFactory.java | 10 +++++----- .../quartz/MethodInvokingJobDetailFactoryBean.java | 6 +++--- .../scheduling/quartz/SchedulerAccessor.java | 6 +++--- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java index ef8c3b03e5..c47497f85e 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java +++ b/spring-context-support/src/main/java/org/springframework/cache/caffeine/CaffeineCache.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -93,8 +93,8 @@ public class CaffeineCache extends AbstractValueAdaptingCache { @Override @Nullable protected Object lookup(Object key) { - if (this.cache instanceof LoadingCache) { - return ((LoadingCache) this.cache).get(key); + if (this.cache instanceof LoadingCache loadingCache) { + return loadingCache.get(key); } return this.cache.getIfPresent(key); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java index 4d2af4b946..793435d03f 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/AbstractJCacheConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,8 +48,8 @@ public abstract class AbstractJCacheConfiguration extends AbstractCachingConfigu protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) { super.useCachingConfigurer(cachingConfigurerSupplier); this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> { - if (config instanceof JCacheConfigurer) { - return ((JCacheConfigurer) config).exceptionCacheResolver(); + if (config instanceof JCacheConfigurer jcacheConfigurer) { + return jcacheConfigurer.exceptionCacheResolver(); } return null; }); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java index 9bc89f8e0a..c5adcac5ac 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/package-info.java @@ -1,10 +1,10 @@ /** - * Support package for declarative JSR-107 caching configuration. Used - * by the regular Spring's caching configuration when it detects the - * JSR-107 API and Spring's JCache implementation. + * Support package for declarative JSR-107 caching configuration. Used by Spring's + * caching configuration when it detects the JSR-107 API and Spring's JCache + * implementation. * - *

Provide an extension of the {@code CachingConfigurer} that exposes - * the exception cache resolver to use, see {@code JCacheConfigurer}. + *

Provides an extension of the {@code CachingConfigurer} that exposes + * the exception cache resolver to use (see {@code JCacheConfigurer}). */ @NonNullApi @NonNullFields diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java index d1f396e979..9bd230ab93 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/DefaultCacheKeyInvocationContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -42,8 +42,8 @@ class DefaultCacheKeyInvocationContext extends DefaultCach public DefaultCacheKeyInvocationContext(AbstractJCacheKeyOperation operation, Object target, Object[] args) { super(operation, target, args); this.keyParameters = operation.getKeyParameters(args); - if (operation instanceof CachePutOperation) { - this.valueParameter = ((CachePutOperation) operation).getValueParameter(args); + if (operation instanceof CachePutOperation cachePutOperation) { + this.valueParameter = cachePutOperation.getValueParameter(args); } else { this.valueParameter = null; diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java index 33898c102b..d74782323d 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/AdaptableJobFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -71,11 +71,11 @@ public class AdaptableJobFactory implements JobFactory { * @see DelegatingJob */ protected Job adaptJob(Object jobObject) throws Exception { - if (jobObject instanceof Job) { - return (Job) jobObject; + if (jobObject instanceof Job job) { + return job; } - else if (jobObject instanceof Runnable) { - return new DelegatingJob((Runnable) jobObject); + else if (jobObject instanceof Runnable runnable) { + return new DelegatingJob(runnable); } else { throw new IllegalArgumentException( diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java index 93470b37c1..cace9ab82e 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/MethodInvokingJobDetailFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -267,9 +267,9 @@ public class MethodInvokingJobDetailFactoryBean extends ArgumentConvertingMethod context.setResult(this.methodInvoker.invoke()); } catch (InvocationTargetException ex) { - if (ex.getTargetException() instanceof JobExecutionException) { + if (ex.getTargetException() instanceof JobExecutionException jobExecutionException) { // -> JobExecutionException, to be logged at info level by Quartz - throw (JobExecutionException) ex.getTargetException(); + throw jobExecutionException; } else { // -> "unhandled exception", to be logged at error level by Quartz diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java index de60cbb9ca..f9d4c72ab3 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -256,8 +256,8 @@ public abstract class SchedulerAccessor implements ResourceLoaderAware { throw tex; } } - if (ex instanceof SchedulerException) { - throw (SchedulerException) ex; + if (ex instanceof SchedulerException schedulerException) { + throw schedulerException; } if (ex instanceof Exception) { throw new SchedulerException("Registration of jobs and triggers failed: " + ex.getMessage(), ex);