diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java index 88724adc12c..041d9aea0ef 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/CacheResolverAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -59,10 +59,9 @@ class CacheResolverAdapter implements CacheResolver { @Override public Collection resolveCaches(CacheOperationInvocationContext context) { - if (!(context instanceof CacheInvocationContext)) { + if (!(context instanceof CacheInvocationContext cacheInvocationContext)) { throw new IllegalStateException("Unexpected context " + context); } - CacheInvocationContext cacheInvocationContext = (CacheInvocationContext) context; javax.cache.Cache cache = this.target.resolveCache(cacheInvocationContext); if (cache == null) { throw new IllegalStateException("Could not resolve cache for " + context + " using " + this.target); diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java index 4b6d7e0fb94..1dbb4210894 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/JCacheOperationSourcePointcut.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -52,10 +52,9 @@ public abstract class JCacheOperationSourcePointcut extends StaticMethodMatcherP if (this == other) { return true; } - if (!(other instanceof JCacheOperationSourcePointcut)) { + if (!(other instanceof JCacheOperationSourcePointcut otherPc)) { return false; } - JCacheOperationSourcePointcut otherPc = (JCacheOperationSourcePointcut) other; return ObjectUtils.nullSafeEquals(getCacheOperationSource(), otherPc.getCacheOperationSource()); } diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java index f2091ab1fb3..1aa56954613 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/interceptor/SimpleExceptionCacheResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -43,10 +43,9 @@ public class SimpleExceptionCacheResolver extends AbstractCacheResolver { @Override protected Collection getCacheNames(CacheOperationInvocationContext context) { BasicOperation operation = context.getOperation(); - if (!(operation instanceof CacheResultOperation)) { + if (!(operation instanceof CacheResultOperation cacheResultOperation)) { throw new IllegalStateException("Could not extract exception cache name from " + operation); } - CacheResultOperation cacheResultOperation = (CacheResultOperation) operation; String exceptionCacheName = cacheResultOperation.getExceptionCacheName(); if (exceptionCacheName != null) { return Collections.singleton(exceptionCacheName); diff --git a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java index 95268a2993e..4e8295f70d3 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java +++ b/spring-context-support/src/main/java/org/springframework/mail/SimpleMailMessage.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 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. @@ -226,10 +226,9 @@ public class SimpleMailMessage implements MailMessage, Serializable { if (this == other) { return true; } - if (!(other instanceof SimpleMailMessage)) { + if (!(other instanceof SimpleMailMessage otherMessage)) { return false; } - SimpleMailMessage otherMessage = (SimpleMailMessage) other; return (ObjectUtils.nullSafeEquals(this.from, otherMessage.from) && ObjectUtils.nullSafeEquals(this.replyTo, otherMessage.replyTo) && ObjectUtils.nullSafeEquals(this.to, otherMessage.to) && diff --git a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java index c056ec623d2..3d7bf4c7b0d 100644 --- a/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java +++ b/spring-context-support/src/main/java/org/springframework/mail/javamail/MimeMessageHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -30,6 +30,7 @@ import jakarta.activation.FileTypeMap; import jakarta.mail.BodyPart; import jakarta.mail.Message; import jakarta.mail.MessagingException; +import jakarta.mail.Part; import jakarta.mail.internet.AddressException; import jakarta.mail.internet.InternetAddress; import jakarta.mail.internet.MimeBodyPart; @@ -91,6 +92,7 @@ import org.springframework.util.Assert; * on the MULTIPART_MODE constants contains more detailed information. * * @author Juergen Hoeller + * @author Sam Brannen * @since 19.01.2004 * @see #setText(String, boolean) * @see #setText(String, String) @@ -427,8 +429,8 @@ public class MimeMessageHelper { */ @Nullable protected String getDefaultEncoding(MimeMessage mimeMessage) { - if (mimeMessage instanceof SmartMimeMessage) { - return ((SmartMimeMessage) mimeMessage).getDefaultEncoding(); + if (mimeMessage instanceof SmartMimeMessage smartMimeMessage) { + return smartMimeMessage.getDefaultEncoding(); } return null; } @@ -449,8 +451,8 @@ public class MimeMessageHelper { * @see ConfigurableMimeFileTypeMap */ protected FileTypeMap getDefaultFileTypeMap(MimeMessage mimeMessage) { - if (mimeMessage instanceof SmartMimeMessage) { - FileTypeMap fileTypeMap = ((SmartMimeMessage) mimeMessage).getDefaultFileTypeMap(); + if (mimeMessage instanceof SmartMimeMessage smartMimeMessage) { + FileTypeMap fileTypeMap = smartMimeMessage.getDefaultFileTypeMap(); if (fileTypeMap != null) { return fileTypeMap; } @@ -908,7 +910,7 @@ public class MimeMessageHelper { Assert.notNull(contentId, "Content ID must not be null"); Assert.notNull(dataSource, "DataSource must not be null"); MimeBodyPart mimeBodyPart = new MimeBodyPart(); - mimeBodyPart.setDisposition(MimeBodyPart.INLINE); + mimeBodyPart.setDisposition(Part.INLINE); mimeBodyPart.setContentID("<" + contentId + ">"); mimeBodyPart.setDataHandler(new DataHandler(dataSource)); getMimeMultipart().addBodyPart(mimeBodyPart); @@ -990,7 +992,7 @@ public class MimeMessageHelper { throws MessagingException { Assert.notNull(inputStreamSource, "InputStreamSource must not be null"); - if (inputStreamSource instanceof Resource && ((Resource) inputStreamSource).isOpen()) { + if (inputStreamSource instanceof Resource resource && resource.isOpen()) { throw new IllegalArgumentException( "Passed-in Resource contains an open stream: invalid argument. " + "JavaMail requires an InputStreamSource that creates a fresh stream for every call."); @@ -1018,7 +1020,7 @@ public class MimeMessageHelper { Assert.notNull(dataSource, "DataSource must not be null"); try { MimeBodyPart mimeBodyPart = new MimeBodyPart(); - mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT); + mimeBodyPart.setDisposition(Part.ATTACHMENT); mimeBodyPart.setFileName(isEncodeFilenames() ? MimeUtility.encodeText(attachmentFilename) : attachmentFilename); mimeBodyPart.setDataHandler(new DataHandler(dataSource)); @@ -1095,7 +1097,7 @@ public class MimeMessageHelper { throws MessagingException { Assert.notNull(inputStreamSource, "InputStreamSource must not be null"); - if (inputStreamSource instanceof Resource && ((Resource) inputStreamSource).isOpen()) { + if (inputStreamSource instanceof Resource resource && resource.isOpen()) { throw new IllegalArgumentException( "Passed-in Resource contains an open stream: invalid argument. " + "JavaMail requires an InputStreamSource that creates a fresh stream for every call."); diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java index 42a80e2a33b..ea136c6e4fb 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/SchedulerAccessorBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 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. @@ -99,8 +99,7 @@ public class SchedulerAccessorBean extends SchedulerAccessor implements BeanFact } protected Scheduler findScheduler(String schedulerName) throws SchedulerException { - if (this.beanFactory instanceof ListableBeanFactory) { - ListableBeanFactory lbf = (ListableBeanFactory) this.beanFactory; + if (this.beanFactory instanceof ListableBeanFactory lbf) { String[] beanNames = lbf.getBeanNamesForType(Scheduler.class); for (String beanName : beanNames) { Scheduler schedulerBean = (Scheduler) lbf.getBean(beanName);