Apply "instanceof pattern matching" in remainder of spring-context module
See gh-30067
This commit is contained in:
parent
d9500e60a1
commit
24de8c6f4c
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -88,22 +88,22 @@ public class SpringCacheAnnotationParser implements CacheAnnotationParser, Seria
|
|||
private Collection<CacheOperation> parseCacheAnnotations(
|
||||
DefaultCacheConfig cachingConfig, AnnotatedElement ae, boolean localOnly) {
|
||||
|
||||
Collection<? extends Annotation> anns = (localOnly ?
|
||||
Collection<? extends Annotation> annotations = (localOnly ?
|
||||
AnnotatedElementUtils.getAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS) :
|
||||
AnnotatedElementUtils.findAllMergedAnnotations(ae, CACHE_OPERATION_ANNOTATIONS));
|
||||
if (anns.isEmpty()) {
|
||||
if (annotations.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Collection<CacheOperation> ops = new ArrayList<>(1);
|
||||
anns.stream().filter(ann -> ann instanceof Cacheable).forEach(
|
||||
ann -> ops.add(parseCacheableAnnotation(ae, cachingConfig, (Cacheable) ann)));
|
||||
anns.stream().filter(ann -> ann instanceof CacheEvict).forEach(
|
||||
ann -> ops.add(parseEvictAnnotation(ae, cachingConfig, (CacheEvict) ann)));
|
||||
anns.stream().filter(ann -> ann instanceof CachePut).forEach(
|
||||
ann -> ops.add(parsePutAnnotation(ae, cachingConfig, (CachePut) ann)));
|
||||
anns.stream().filter(ann -> ann instanceof Caching).forEach(
|
||||
ann -> parseCachingAnnotation(ae, cachingConfig, (Caching) ann, ops));
|
||||
Collection<CacheOperation> ops = new ArrayList<>(1);
|
||||
annotations.stream().filter(Cacheable.class::isInstance).map(Cacheable.class::cast).forEach(
|
||||
cacheable -> ops.add(parseCacheableAnnotation(ae, cachingConfig, cacheable)));
|
||||
annotations.stream().filter(CacheEvict.class::isInstance).map(CacheEvict.class::cast).forEach(
|
||||
cacheEvict -> ops.add(parseEvictAnnotation(ae, cachingConfig, cacheEvict)));
|
||||
annotations.stream().filter(CachePut.class::isInstance).map(CachePut.class::cast).forEach(
|
||||
cachePut -> ops.add(parsePutAnnotation(ae, cachingConfig, cachePut)));
|
||||
annotations.stream().filter(Caching.class::isInstance).map(Caching.class::cast).forEach(
|
||||
caching -> parseCachingAnnotation(ae, cachingConfig, caching, ops));
|
||||
return ops;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -772,11 +772,11 @@ public abstract class CacheAspectSupport extends AbstractCacheInvoker
|
|||
|
||||
protected boolean canPutToCache(@Nullable Object value) {
|
||||
String unless = "";
|
||||
if (this.metadata.operation instanceof CacheableOperation) {
|
||||
unless = ((CacheableOperation) this.metadata.operation).getUnless();
|
||||
if (this.metadata.operation instanceof CacheableOperation cacheableOperation) {
|
||||
unless = cacheableOperation.getUnless();
|
||||
}
|
||||
else if (this.metadata.operation instanceof CachePutOperation) {
|
||||
unless = ((CachePutOperation) this.metadata.operation).getUnless();
|
||||
else if (this.metadata.operation instanceof CachePutOperation cachePutOperation) {
|
||||
unless = cachePutOperation.getUnless();
|
||||
}
|
||||
if (StringUtils.hasText(unless)) {
|
||||
EvaluationContext evaluationContext = createEvaluationContext(value);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -235,11 +235,11 @@ public abstract class AnnotationConfigUtils {
|
|||
|
||||
@Nullable
|
||||
private static DefaultListableBeanFactory unwrapDefaultListableBeanFactory(BeanDefinitionRegistry registry) {
|
||||
if (registry instanceof DefaultListableBeanFactory) {
|
||||
return (DefaultListableBeanFactory) registry;
|
||||
if (registry instanceof DefaultListableBeanFactory dlbf) {
|
||||
return dlbf;
|
||||
}
|
||||
else if (registry instanceof GenericApplicationContext) {
|
||||
return ((GenericApplicationContext) registry).getDefaultListableBeanFactory();
|
||||
else if (registry instanceof GenericApplicationContext gac) {
|
||||
return gac.getDefaultListableBeanFactory();
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -370,8 +370,8 @@ public class ConfigurationClassPostProcessor implements BeanDefinitionRegistryPo
|
|||
|
||||
// Detect any custom bean name generation strategy supplied through the enclosing application context
|
||||
SingletonBeanRegistry sbr = null;
|
||||
if (registry instanceof SingletonBeanRegistry) {
|
||||
sbr = (SingletonBeanRegistry) registry;
|
||||
if (registry instanceof SingletonBeanRegistry _sbr) {
|
||||
sbr = _sbr;
|
||||
if (!this.localBeanNameGeneratorSet) {
|
||||
BeanNameGenerator generator = (BeanNameGenerator) sbr.getSingleton(
|
||||
AnnotationConfigUtils.CONFIGURATION_BEAN_NAME_GENERATOR);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -101,15 +101,15 @@ public abstract class ConfigurationClassUtils {
|
|||
}
|
||||
|
||||
AnnotationMetadata metadata;
|
||||
if (beanDef instanceof AnnotatedBeanDefinition &&
|
||||
className.equals(((AnnotatedBeanDefinition) beanDef).getMetadata().getClassName())) {
|
||||
if (beanDef instanceof AnnotatedBeanDefinition annotatedBd &&
|
||||
className.equals(annotatedBd.getMetadata().getClassName())) {
|
||||
// Can reuse the pre-parsed metadata from the given BeanDefinition...
|
||||
metadata = ((AnnotatedBeanDefinition) beanDef).getMetadata();
|
||||
metadata = annotatedBd.getMetadata();
|
||||
}
|
||||
else if (beanDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) beanDef).hasBeanClass()) {
|
||||
else if (beanDef instanceof AbstractBeanDefinition abstractBd && abstractBd.hasBeanClass()) {
|
||||
// Check already loaded Class if present...
|
||||
// since we possibly can't even load the class file for this Class.
|
||||
Class<?> beanClass = ((AbstractBeanDefinition) beanDef).getBeanClass();
|
||||
Class<?> beanClass = abstractBd.getBeanClass();
|
||||
if (BeanFactoryPostProcessor.class.isAssignableFrom(beanClass) ||
|
||||
BeanPostProcessor.class.isAssignableFrom(beanClass) ||
|
||||
AopInfrastructureBean.class.isAssignableFrom(beanClass) ||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -184,8 +184,8 @@ public class EventListenerMethodProcessor
|
|||
Method methodToUse = AopUtils.selectInvocableMethod(method, context.getType(beanName));
|
||||
ApplicationListener<?> applicationListener =
|
||||
factory.createApplicationListener(beanName, targetType, methodToUse);
|
||||
if (applicationListener instanceof ApplicationListenerMethodAdapter) {
|
||||
((ApplicationListenerMethodAdapter) applicationListener).init(context, this.evaluator);
|
||||
if (applicationListener instanceof ApplicationListenerMethodAdapter alma) {
|
||||
alma.init(context, this.evaluator);
|
||||
}
|
||||
context.addApplicationListener(applicationListener);
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -67,12 +67,12 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public boolean supportsEventType(ResolvableType eventType) {
|
||||
if (this.delegate instanceof GenericApplicationListener) {
|
||||
return ((GenericApplicationListener) this.delegate).supportsEventType(eventType);
|
||||
if (this.delegate instanceof GenericApplicationListener gal) {
|
||||
return gal.supportsEventType(eventType);
|
||||
}
|
||||
else if (this.delegate instanceof SmartApplicationListener) {
|
||||
else if (this.delegate instanceof SmartApplicationListener sal) {
|
||||
Class<? extends ApplicationEvent> eventClass = (Class<? extends ApplicationEvent>) eventType.resolve();
|
||||
return (eventClass != null && ((SmartApplicationListener) this.delegate).supportsEventType(eventClass));
|
||||
return (eventClass != null && sal.supportsEventType(eventClass));
|
||||
}
|
||||
else {
|
||||
return (this.declaredEventType == null || this.declaredEventType.isAssignableFrom(eventType));
|
||||
|
|
@ -81,19 +81,17 @@ public class GenericApplicationListenerAdapter implements GenericApplicationList
|
|||
|
||||
@Override
|
||||
public boolean supportsSourceType(@Nullable Class<?> sourceType) {
|
||||
return !(this.delegate instanceof SmartApplicationListener) ||
|
||||
((SmartApplicationListener) this.delegate).supportsSourceType(sourceType);
|
||||
return (!(this.delegate instanceof SmartApplicationListener sal) || sal.supportsSourceType(sourceType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return (this.delegate instanceof Ordered ? ((Ordered) this.delegate).getOrder() : Ordered.LOWEST_PRECEDENCE);
|
||||
return (this.delegate instanceof Ordered ordered ? ordered.getOrder() : Ordered.LOWEST_PRECEDENCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getListenerId() {
|
||||
return (this.delegate instanceof SmartApplicationListener ?
|
||||
((SmartApplicationListener) this.delegate).getListenerId() : "");
|
||||
return (this.delegate instanceof SmartApplicationListener sal ? sal.getListenerId() : "");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -178,8 +178,8 @@ public class SimpleApplicationEventMulticaster extends AbstractApplicationEventM
|
|||
catch (ClassCastException ex) {
|
||||
String msg = ex.getMessage();
|
||||
if (msg == null || matchesClassCastMessage(msg, event.getClass()) ||
|
||||
(event instanceof PayloadApplicationEvent &&
|
||||
matchesClassCastMessage(msg, ((PayloadApplicationEvent) event).getPayload().getClass()))) {
|
||||
(event instanceof PayloadApplicationEvent payloadEvent &&
|
||||
matchesClassCastMessage(msg, payloadEvent.getPayload().getClass()))) {
|
||||
// Possibly a lambda-defined listener which we could not resolve the generic event type for
|
||||
// -> let's suppress the exception.
|
||||
Log loggerToUse = this.lazyLogger;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -51,8 +51,8 @@ public class SourceFilteringListener implements GenericApplicationListener {
|
|||
*/
|
||||
public SourceFilteringListener(Object source, ApplicationListener<?> delegate) {
|
||||
this.source = source;
|
||||
this.delegate = (delegate instanceof GenericApplicationListener ?
|
||||
(GenericApplicationListener) delegate : new GenericApplicationListenerAdapter(delegate));
|
||||
this.delegate = (delegate instanceof GenericApplicationListener gal ? gal :
|
||||
new GenericApplicationListenerAdapter(delegate));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -152,8 +152,8 @@ public final class LocaleContextHolder {
|
|||
*/
|
||||
public static void setLocale(@Nullable Locale locale, boolean inheritable) {
|
||||
LocaleContext localeContext = getLocaleContext();
|
||||
TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext ?
|
||||
((TimeZoneAwareLocaleContext) localeContext).getTimeZone() : null);
|
||||
TimeZone timeZone = (localeContext instanceof TimeZoneAwareLocaleContext timeZoneAware ?
|
||||
timeZoneAware.getTimeZone() : null);
|
||||
if (timeZone != null) {
|
||||
localeContext = new SimpleTimeZoneAwareLocaleContext(locale, timeZone);
|
||||
}
|
||||
|
|
@ -324,8 +324,8 @@ public final class LocaleContextHolder {
|
|||
* @see java.util.TimeZone#getDefault()
|
||||
*/
|
||||
public static TimeZone getTimeZone(@Nullable LocaleContext localeContext) {
|
||||
if (localeContext instanceof TimeZoneAwareLocaleContext) {
|
||||
TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
|
||||
if (localeContext instanceof TimeZoneAwareLocaleContext timeZoneAware) {
|
||||
TimeZone timeZone = timeZoneAware.getTimeZone();
|
||||
if (timeZone != null) {
|
||||
return timeZone;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -128,12 +128,12 @@ public class DefaultContextLoadTimeWeaver implements LoadTimeWeaver, BeanClassLo
|
|||
|
||||
@Override
|
||||
public void destroy() {
|
||||
if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver) {
|
||||
if (this.loadTimeWeaver instanceof InstrumentationLoadTimeWeaver iltw) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Removing all registered transformers for class loader: " +
|
||||
this.loadTimeWeaver.getInstrumentableClassLoader().getClass().getName());
|
||||
}
|
||||
((InstrumentationLoadTimeWeaver) this.loadTimeWeaver).removeTransformers();
|
||||
iltw.removeTransformers();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -92,7 +92,7 @@ public class LoadTimeWeaverAwareProcessor implements BeanPostProcessor, BeanFact
|
|||
|
||||
@Override
|
||||
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
|
||||
if (bean instanceof LoadTimeWeaverAware) {
|
||||
if (bean instanceof LoadTimeWeaverAware loadTimeWeaverAware) {
|
||||
LoadTimeWeaver ltw = this.loadTimeWeaver;
|
||||
if (ltw == null) {
|
||||
Assert.state(this.beanFactory != null,
|
||||
|
|
@ -100,7 +100,7 @@ public class LoadTimeWeaverAwareProcessor implements BeanPostProcessor, BeanFact
|
|||
ltw = this.beanFactory.getBean(
|
||||
ConfigurableApplicationContext.LOAD_TIME_WEAVER_BEAN_NAME, LoadTimeWeaver.class);
|
||||
}
|
||||
((LoadTimeWeaverAware) bean).setLoadTimeWeaver(ltw);
|
||||
loadTimeWeaverAware.setLoadTimeWeaver(ltw);
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -96,8 +96,8 @@ public class DateTimeContext {
|
|||
}
|
||||
else {
|
||||
LocaleContext localeContext = LocaleContextHolder.getLocaleContext();
|
||||
if (localeContext instanceof TimeZoneAwareLocaleContext) {
|
||||
TimeZone timeZone = ((TimeZoneAwareLocaleContext) localeContext).getTimeZone();
|
||||
if (localeContext instanceof TimeZoneAwareLocaleContext timeZoneAware) {
|
||||
TimeZone timeZone = timeZoneAware.getTimeZone();
|
||||
if (timeZone != null) {
|
||||
formatter = formatter.withZone(timeZone.toZoneId());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -77,8 +77,8 @@ final class DateTimeConverters {
|
|||
}
|
||||
|
||||
private static ZonedDateTime calendarToZonedDateTime(Calendar source) {
|
||||
if (source instanceof GregorianCalendar) {
|
||||
return ((GregorianCalendar) source).toZonedDateTime();
|
||||
if (source instanceof GregorianCalendar gc) {
|
||||
return gc.toZonedDateTime();
|
||||
}
|
||||
else {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(source.getTimeInMillis()),
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 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.
|
||||
|
|
@ -37,8 +37,8 @@ public class PercentStyleFormatter extends AbstractNumberFormatter {
|
|||
@Override
|
||||
protected NumberFormat getNumberFormat(Locale locale) {
|
||||
NumberFormat format = NumberFormat.getPercentInstance(locale);
|
||||
if (format instanceof DecimalFormat) {
|
||||
((DecimalFormat) format).setParseBigDecimal(true);
|
||||
if (format instanceof DecimalFormat decimalFormat) {
|
||||
decimalFormat.setParseBigDecimal(true);
|
||||
}
|
||||
return format;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -117,9 +117,8 @@ public class FormattingConversionService extends GenericConversionService
|
|||
|
||||
private static <T> Class<?> getFieldType(T instance, Class<T> genericInterface) {
|
||||
Class<?> fieldType = GenericTypeResolver.resolveTypeArgument(instance.getClass(), genericInterface);
|
||||
if (fieldType == null && instance instanceof DecoratingProxy) {
|
||||
fieldType = GenericTypeResolver.resolveTypeArgument(
|
||||
((DecoratingProxy) instance).getDecoratedClass(), genericInterface);
|
||||
if (fieldType == null && instance instanceof DecoratingProxy decoratingProxy) {
|
||||
fieldType = GenericTypeResolver.resolveTypeArgument(decoratingProxy.getDecoratedClass(), genericInterface);
|
||||
}
|
||||
Assert.notNull(fieldType, () -> "Unable to extract the parameterized field type from " +
|
||||
ClassUtils.getShortName(genericInterface) + " [" + instance.getClass().getName() +
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -145,12 +145,12 @@ public class FormattingConversionServiceFactoryBean
|
|||
|
||||
private void registerFormatters(FormattingConversionService conversionService) {
|
||||
if (this.formatters != null) {
|
||||
for (Object formatter : this.formatters) {
|
||||
if (formatter instanceof Formatter<?>) {
|
||||
conversionService.addFormatter((Formatter<?>) formatter);
|
||||
for (Object candidate : this.formatters) {
|
||||
if (candidate instanceof Formatter<?> formatter) {
|
||||
conversionService.addFormatter(formatter);
|
||||
}
|
||||
else if (formatter instanceof AnnotationFormatterFactory<?>) {
|
||||
conversionService.addFormatterForFieldAnnotation((AnnotationFormatterFactory<?>) formatter);
|
||||
else if (candidate instanceof AnnotationFormatterFactory<?> factory) {
|
||||
conversionService.addFormatterForFieldAnnotation(factory);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException(
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -441,11 +441,11 @@ public class MBeanClientInterceptor
|
|||
catch (RuntimeOperationsException ex) {
|
||||
// This one is only thrown by the JMX 1.2 RI, not by the JDK 1.5 JMX code.
|
||||
RuntimeException rex = ex.getTargetException();
|
||||
if (rex instanceof RuntimeMBeanException) {
|
||||
throw ((RuntimeMBeanException) rex).getTargetException();
|
||||
if (rex instanceof RuntimeMBeanException runtimeMBeanException) {
|
||||
throw runtimeMBeanException.getTargetException();
|
||||
}
|
||||
else if (rex instanceof RuntimeErrorException) {
|
||||
throw ((RuntimeErrorException) rex).getTargetError();
|
||||
else if (rex instanceof RuntimeErrorException runtimeErrorException) {
|
||||
throw runtimeErrorException.getTargetError();
|
||||
}
|
||||
else {
|
||||
throw rex;
|
||||
|
|
|
|||
|
|
@ -402,8 +402,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
*/
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (beanFactory instanceof ListableBeanFactory) {
|
||||
this.beanFactory = (ListableBeanFactory) beanFactory;
|
||||
if (beanFactory instanceof ListableBeanFactory lbf) {
|
||||
this.beanFactory = lbf;
|
||||
}
|
||||
else {
|
||||
logger.debug("MBeanExporter not running in a ListableBeanFactory: autodetection of MBeans not available.");
|
||||
|
|
@ -543,8 +543,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
}
|
||||
// Allow the assembler a chance to vote for bean inclusion.
|
||||
if ((mode == AUTODETECT_ASSEMBLER || mode == AUTODETECT_ALL) &&
|
||||
this.assembler instanceof AutodetectCapableMBeanInfoAssembler) {
|
||||
autodetect(this.beans, ((AutodetectCapableMBeanInfoAssembler) this.assembler)::includeBean);
|
||||
this.assembler instanceof AutodetectCapableMBeanInfoAssembler autodetectCapableAssembler) {
|
||||
autodetect(this.beans, autodetectCapableAssembler::includeBean);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -561,8 +561,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
* @see org.springframework.beans.factory.config.BeanDefinition#isLazyInit
|
||||
*/
|
||||
protected boolean isBeanDefinitionLazyInit(ListableBeanFactory beanFactory, String beanName) {
|
||||
return (beanFactory instanceof ConfigurableListableBeanFactory && beanFactory.containsBeanDefinition(beanName) &&
|
||||
((ConfigurableListableBeanFactory) beanFactory).getBeanDefinition(beanName).isLazyInit());
|
||||
return (beanFactory instanceof ConfigurableListableBeanFactory clbf && beanFactory.containsBeanDefinition(beanName) &&
|
||||
clbf.getBeanDefinition(beanName).isLazyInit());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -748,8 +748,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
* if the retrieved {@code ObjectName} is malformed
|
||||
*/
|
||||
protected ObjectName getObjectName(Object bean, @Nullable String beanKey) throws MalformedObjectNameException {
|
||||
if (bean instanceof SelfNaming) {
|
||||
return ((SelfNaming) bean).getObjectName();
|
||||
if (bean instanceof SelfNaming selfNaming) {
|
||||
return selfNaming.getObjectName();
|
||||
}
|
||||
else {
|
||||
return this.namingStrategy.getObjectName(bean, beanKey);
|
||||
|
|
@ -869,8 +869,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
Assert.state(this.beanFactory != null, "No BeanFactory set");
|
||||
Set<String> beanNames = new LinkedHashSet<>(this.beanFactory.getBeanDefinitionCount());
|
||||
Collections.addAll(beanNames, this.beanFactory.getBeanDefinitionNames());
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
Collections.addAll(beanNames, ((ConfigurableBeanFactory) this.beanFactory).getSingletonNames());
|
||||
if (this.beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||
Collections.addAll(beanNames, cbf.getSingletonNames());
|
||||
}
|
||||
|
||||
for (String beanName : beanNames) {
|
||||
|
|
@ -925,8 +925,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
* Return whether the specified bean definition should be considered as abstract.
|
||||
*/
|
||||
private boolean isBeanDefinitionAbstract(ListableBeanFactory beanFactory, String beanName) {
|
||||
return (beanFactory instanceof ConfigurableListableBeanFactory && beanFactory.containsBeanDefinition(beanName) &&
|
||||
((ConfigurableListableBeanFactory) beanFactory).getBeanDefinition(beanName).isAbstract());
|
||||
return (beanFactory instanceof ConfigurableListableBeanFactory clbf && beanFactory.containsBeanDefinition(beanName) &&
|
||||
clbf.getBeanDefinition(beanName).isAbstract());
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -941,9 +941,8 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
private void injectNotificationPublisherIfNecessary(
|
||||
Object managedResource, @Nullable ModelMBean modelMBean, @Nullable ObjectName objectName) {
|
||||
|
||||
if (managedResource instanceof NotificationPublisherAware && modelMBean != null && objectName != null) {
|
||||
((NotificationPublisherAware) managedResource).setNotificationPublisher(
|
||||
new ModelMBeanNotificationPublisher(modelMBean, objectName, managedResource));
|
||||
if (managedResource instanceof NotificationPublisherAware npa && modelMBean != null && objectName != null) {
|
||||
npa.setNotificationPublisher(new ModelMBeanNotificationPublisher(modelMBean, objectName, managedResource));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -66,8 +66,8 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
|||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
||||
this.embeddedValueResolver = new EmbeddedValueResolver((ConfigurableBeanFactory) beanFactory);
|
||||
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||
this.embeddedValueResolver = new EmbeddedValueResolver(cbf);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,8 +92,8 @@ public class AnnotationJmxAttributeSource implements JmxAttributeSource, BeanFac
|
|||
map.forEach((attrName, attrValue) -> {
|
||||
if (!"value".equals(attrName)) {
|
||||
Object value = attrValue;
|
||||
if (this.embeddedValueResolver != null && value instanceof String) {
|
||||
value = this.embeddedValueResolver.resolveStringValue((String) value);
|
||||
if (this.embeddedValueResolver != null && value instanceof String text) {
|
||||
value = this.embeddedValueResolver.resolveStringValue(text);
|
||||
}
|
||||
list.add(new PropertyValue(attrName, value));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -90,8 +90,8 @@ public class ModelMBeanNotificationPublisher implements NotificationPublisher {
|
|||
Assert.notNull(notification, "Notification must not be null");
|
||||
replaceNotificationSourceIfNecessary(notification);
|
||||
try {
|
||||
if (notification instanceof AttributeChangeNotification) {
|
||||
this.modelMBean.sendAttributeChangeNotification((AttributeChangeNotification) notification);
|
||||
if (notification instanceof AttributeChangeNotification acn) {
|
||||
this.modelMBean.sendAttributeChangeNotification(acn);
|
||||
}
|
||||
else {
|
||||
this.modelMBean.sendNotification(notification);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -36,23 +36,22 @@ public final class ObjectNameManager {
|
|||
|
||||
|
||||
/**
|
||||
* Retrieve the {@code ObjectName} instance corresponding to the supplied name.
|
||||
* @param objectName the {@code ObjectName} in {@code ObjectName} or
|
||||
* {@code String} format
|
||||
* Retrieve the {@link ObjectName} instance corresponding to the supplied name.
|
||||
* @param name the name in {@code ObjectName} or {@code String} format
|
||||
* @return the {@code ObjectName} instance
|
||||
* @throws MalformedObjectNameException in case of an invalid object name specification
|
||||
* @see ObjectName#ObjectName(String)
|
||||
* @see ObjectName#getInstance(String)
|
||||
*/
|
||||
public static ObjectName getInstance(Object objectName) throws MalformedObjectNameException {
|
||||
if (objectName instanceof ObjectName) {
|
||||
return (ObjectName) objectName;
|
||||
public static ObjectName getInstance(Object name) throws MalformedObjectNameException {
|
||||
if (name instanceof ObjectName objectName) {
|
||||
return objectName;
|
||||
}
|
||||
if (!(objectName instanceof String)) {
|
||||
if (!(name instanceof String text)) {
|
||||
throw new MalformedObjectNameException("Invalid ObjectName value type [" +
|
||||
objectName.getClass().getName() + "]: only ObjectName and String supported.");
|
||||
name.getClass().getName() + "]: only ObjectName and String supported.");
|
||||
}
|
||||
return getInstance((String) objectName);
|
||||
return getInstance(text);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -178,10 +178,10 @@ public class JndiObjectFactoryBean extends JndiObjectLocator
|
|||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (beanFactory instanceof ConfigurableBeanFactory) {
|
||||
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||
// Just optional - for getting a specifically configured TypeConverter if needed.
|
||||
// We'll simply fall back to a SimpleTypeConverter if no specific one available.
|
||||
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
|
||||
this.beanFactory = cbf;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -139,8 +139,8 @@ public class AsyncAnnotationAdvisor extends AbstractPointcutAdvisor implements B
|
|||
*/
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (this.advice instanceof BeanFactoryAware) {
|
||||
((BeanFactoryAware) this.advice).setBeanFactory(beanFactory);
|
||||
if (this.advice instanceof BeanFactoryAware beanFactoryAware) {
|
||||
beanFactoryAware.setBeanFactory(beanFactory);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -94,8 +94,7 @@ public class AsyncResult<V> implements ListenableFuture<V> {
|
|||
@Nullable
|
||||
public V get() throws ExecutionException {
|
||||
if (this.executionException != null) {
|
||||
throw (this.executionException instanceof ExecutionException ?
|
||||
(ExecutionException) this.executionException :
|
||||
throw (this.executionException instanceof ExecutionException execEx ? execEx :
|
||||
new ExecutionException(this.executionException));
|
||||
}
|
||||
return this.value;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -244,9 +244,8 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
this.registrar.setScheduler(this.scheduler);
|
||||
}
|
||||
|
||||
if (this.beanFactory instanceof ListableBeanFactory) {
|
||||
Map<String, SchedulingConfigurer> beans =
|
||||
((ListableBeanFactory) this.beanFactory).getBeansOfType(SchedulingConfigurer.class);
|
||||
if (this.beanFactory instanceof ListableBeanFactory lbf) {
|
||||
Map<String, SchedulingConfigurer> beans = lbf.getBeansOfType(SchedulingConfigurer.class);
|
||||
List<SchedulingConfigurer> configurers = new ArrayList<>(beans.values());
|
||||
AnnotationAwareOrderComparator.sort(configurers);
|
||||
for (SchedulingConfigurer configurer : configurers) {
|
||||
|
|
@ -322,16 +321,15 @@ public class ScheduledAnnotationBeanPostProcessor
|
|||
private <T> T resolveSchedulerBean(BeanFactory beanFactory, Class<T> schedulerType, boolean byName) {
|
||||
if (byName) {
|
||||
T scheduler = beanFactory.getBean(DEFAULT_TASK_SCHEDULER_BEAN_NAME, schedulerType);
|
||||
if (this.beanName != null && this.beanFactory instanceof ConfigurableBeanFactory) {
|
||||
((ConfigurableBeanFactory) this.beanFactory).registerDependentBean(
|
||||
DEFAULT_TASK_SCHEDULER_BEAN_NAME, this.beanName);
|
||||
if (this.beanName != null && this.beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||
cbf.registerDependentBean(DEFAULT_TASK_SCHEDULER_BEAN_NAME, this.beanName);
|
||||
}
|
||||
return scheduler;
|
||||
}
|
||||
else if (beanFactory instanceof AutowireCapableBeanFactory) {
|
||||
NamedBeanHolder<T> holder = ((AutowireCapableBeanFactory) beanFactory).resolveNamedBean(schedulerType);
|
||||
if (this.beanName != null && beanFactory instanceof ConfigurableBeanFactory) {
|
||||
((ConfigurableBeanFactory) beanFactory).registerDependentBean(holder.getBeanName(), this.beanName);
|
||||
else if (beanFactory instanceof AutowireCapableBeanFactory acbf) {
|
||||
NamedBeanHolder<T> holder = acbf.resolveNamedBean(schedulerType);
|
||||
if (this.beanName != null && beanFactory instanceof ConfigurableBeanFactory cbf) {
|
||||
cbf.registerDependentBean(holder.getBeanName(), this.beanName);
|
||||
}
|
||||
return holder.getBeanInstance();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -231,10 +231,10 @@ public class ConcurrentTaskExecutor implements AsyncListenableTaskExecutor, Sche
|
|||
|
||||
public static Runnable buildManagedTask(Runnable task, String identityName) {
|
||||
Map<String, String> properties;
|
||||
if (task instanceof SchedulingAwareRunnable) {
|
||||
if (task instanceof SchedulingAwareRunnable schedulingAwareRunnable) {
|
||||
properties = new HashMap<>(4);
|
||||
properties.put(ManagedTask.LONGRUNNING_HINT,
|
||||
Boolean.toString(((SchedulingAwareRunnable) task).isLongLived()));
|
||||
Boolean.toString(schedulingAwareRunnable.isLongLived()));
|
||||
}
|
||||
else {
|
||||
properties = new HashMap<>(2);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -239,8 +239,8 @@ public abstract class ExecutorConfigurationSupport extends CustomizableThreadFac
|
|||
* @see RunnableFuture#cancel(boolean)
|
||||
*/
|
||||
protected void cancelRemainingTask(Runnable task) {
|
||||
if (task instanceof Future) {
|
||||
((Future<?>) task).cancel(true);
|
||||
if (task instanceof Future<?> future) {
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -38,7 +38,7 @@ import org.springframework.util.ObjectUtils;
|
|||
*
|
||||
* <p>Allows for registration of {@link ScheduledExecutorTask ScheduledExecutorTasks},
|
||||
* automatically starting the {@link ScheduledExecutorService} on initialization and
|
||||
* cancelling it on destruction of the context. In scenarios that only require static
|
||||
* canceling it on destruction of the context. In scenarios that only require static
|
||||
* registration of tasks at startup, there is no need to access the
|
||||
* {@link ScheduledExecutorService} instance itself in application code at all;
|
||||
* {@code ScheduledExecutorFactoryBean} is then just being used for lifecycle integration.
|
||||
|
|
@ -153,8 +153,8 @@ public class ScheduledExecutorFactoryBean extends ExecutorConfigurationSupport
|
|||
createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
|
||||
|
||||
if (this.removeOnCancelPolicy) {
|
||||
if (executor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) executor).setRemoveOnCancelPolicy(true);
|
||||
if (executor instanceof ScheduledThreadPoolExecutor threadPoolExecutor) {
|
||||
threadPoolExecutor.setRemoveOnCancelPolicy(true);
|
||||
}
|
||||
else {
|
||||
logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -423,8 +423,8 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
|||
super.cancelRemainingTask(task);
|
||||
// Cancel associated user-level Future handle as well
|
||||
Object original = this.decoratedTaskMap.get(task);
|
||||
if (original instanceof Future) {
|
||||
((Future<?>) original).cancel(true);
|
||||
if (original instanceof Future<?> future) {
|
||||
future.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -91,8 +91,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
*/
|
||||
public void setPoolSize(int poolSize) {
|
||||
Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher");
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setCorePoolSize(poolSize);
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor threadPoolExecutor) {
|
||||
threadPoolExecutor.setCorePoolSize(poolSize);
|
||||
}
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
|
@ -105,8 +105,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
* @see ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy
|
||||
*/
|
||||
public void setRemoveOnCancelPolicy(boolean flag) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(flag);
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor threadPoolExecutor) {
|
||||
threadPoolExecutor.setRemoveOnCancelPolicy(flag);
|
||||
}
|
||||
this.removeOnCancelPolicy = flag;
|
||||
}
|
||||
|
|
@ -120,8 +120,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
* @see ScheduledThreadPoolExecutor#setContinueExistingPeriodicTasksAfterShutdownPolicy
|
||||
*/
|
||||
public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean flag) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setContinueExistingPeriodicTasksAfterShutdownPolicy(flag);
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor threadPoolExecutor) {
|
||||
threadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(flag);
|
||||
}
|
||||
this.continueExistingPeriodicTasksAfterShutdownPolicy = flag;
|
||||
}
|
||||
|
|
@ -135,8 +135,8 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
* @see ScheduledThreadPoolExecutor#setExecuteExistingDelayedTasksAfterShutdownPolicy
|
||||
*/
|
||||
public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean flag) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setExecuteExistingDelayedTasksAfterShutdownPolicy(flag);
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor threadPoolExecutor) {
|
||||
threadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(flag);
|
||||
}
|
||||
this.executeExistingDelayedTasksAfterShutdownPolicy = flag;
|
||||
}
|
||||
|
|
@ -170,15 +170,15 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
|||
|
||||
this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
|
||||
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor scheduledPoolExecutor) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor threadPoolExecutor) {
|
||||
if (this.removeOnCancelPolicy) {
|
||||
scheduledPoolExecutor.setRemoveOnCancelPolicy(true);
|
||||
threadPoolExecutor.setRemoveOnCancelPolicy(true);
|
||||
}
|
||||
if (this.continueExistingPeriodicTasksAfterShutdownPolicy) {
|
||||
scheduledPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
|
||||
threadPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
|
||||
}
|
||||
if (!this.executeExistingDelayedTasksAfterShutdownPolicy) {
|
||||
scheduledPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
threadPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -111,11 +111,11 @@ public class ScheduledTaskRegistrar implements ScheduledTaskHolder, Initializing
|
|||
if (scheduler == null) {
|
||||
this.taskScheduler = null;
|
||||
}
|
||||
else if (scheduler instanceof TaskScheduler) {
|
||||
this.taskScheduler = (TaskScheduler) scheduler;
|
||||
else if (scheduler instanceof TaskScheduler ts) {
|
||||
this.taskScheduler = ts;
|
||||
}
|
||||
else if (scheduler instanceof ScheduledExecutorService) {
|
||||
this.taskScheduler = new ConcurrentTaskScheduler(((ScheduledExecutorService) scheduler));
|
||||
else if (scheduler instanceof ScheduledExecutorService ses) {
|
||||
this.taskScheduler = new ConcurrentTaskScheduler(ses);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Unsupported scheduler type: " + scheduler.getClass());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -114,9 +114,8 @@ public class CronTrigger implements Trigger {
|
|||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
return (this == other || (other instanceof CronTrigger &&
|
||||
this.expression.equals(((CronTrigger) other).expression)));
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return (this == obj || (obj instanceof CronTrigger that && this.expression.equals(that.expression)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -63,8 +63,8 @@ public abstract class TaskUtils {
|
|||
public static DelegatingErrorHandlingRunnable decorateTaskWithErrorHandler(
|
||||
Runnable task, @Nullable ErrorHandler errorHandler, boolean isRepeatingTask) {
|
||||
|
||||
if (task instanceof DelegatingErrorHandlingRunnable) {
|
||||
return (DelegatingErrorHandlingRunnable) task;
|
||||
if (task instanceof DelegatingErrorHandlingRunnable dehRunnable) {
|
||||
return dehRunnable;
|
||||
}
|
||||
ErrorHandler eh = (errorHandler != null ? errorHandler : getDefaultErrorHandler(isRepeatingTask));
|
||||
return new DelegatingErrorHandlingRunnable(task, eh);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -137,10 +137,10 @@ public class BshScriptFactory implements ScriptFactory, BeanClassLoaderAware {
|
|||
// New script content: Let's check whether it evaluates to a Class.
|
||||
Object result = BshScriptUtils.evaluateBshScript(
|
||||
scriptSource.getScriptAsString(), actualInterfaces, this.beanClassLoader);
|
||||
if (result instanceof Class) {
|
||||
if (result instanceof Class<?> type) {
|
||||
// A Class: We'll cache the Class here and create an instance
|
||||
// outside the synchronized block.
|
||||
this.scriptClass = (Class<?>) result;
|
||||
this.scriptClass = type;
|
||||
}
|
||||
else {
|
||||
// Not a Class: OK, we'll simply create BeanShell objects
|
||||
|
|
|
|||
|
|
@ -122,8 +122,8 @@ public abstract class BshScriptUtils {
|
|||
interpreter.setClassLoader(classLoader);
|
||||
}
|
||||
Object result = interpreter.eval(scriptSource);
|
||||
if (result instanceof Class) {
|
||||
return (Class<?>) result;
|
||||
if (result instanceof Class<?> clazz) {
|
||||
return clazz;
|
||||
}
|
||||
else if (result != null) {
|
||||
return result.getClass();
|
||||
|
|
@ -199,8 +199,8 @@ public abstract class BshScriptUtils {
|
|||
if (result == Primitive.NULL || result == Primitive.VOID) {
|
||||
return null;
|
||||
}
|
||||
if (result instanceof Primitive) {
|
||||
return ((Primitive) result).getValue();
|
||||
if (result instanceof Primitive primitive) {
|
||||
return primitive.getValue();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -209,13 +209,12 @@ public abstract class BshScriptUtils {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isProxyForSameBshObject(Object other) {
|
||||
if (!Proxy.isProxyClass(other.getClass())) {
|
||||
private boolean isProxyForSameBshObject(Object obj) {
|
||||
if (!Proxy.isProxyClass(obj.getClass())) {
|
||||
return false;
|
||||
}
|
||||
InvocationHandler ih = Proxy.getInvocationHandler(other);
|
||||
return (ih instanceof BshObjectInvocationHandler &&
|
||||
this.xt.equals(((BshObjectInvocationHandler) ih).xt));
|
||||
InvocationHandler ih = Proxy.getInvocationHandler(obj);
|
||||
return (ih instanceof BshObjectInvocationHandler that && this.xt.equals(that.xt));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -109,8 +109,8 @@ public class GroovyScriptEvaluator implements ScriptEvaluator, BeanClassLoaderAw
|
|||
GroovyShell groovyShell = new GroovyShell(
|
||||
this.classLoader, new Binding(arguments), this.compilerConfiguration);
|
||||
try {
|
||||
String filename = (script instanceof ResourceScriptSource ?
|
||||
((ResourceScriptSource) script).getResource().getFilename() : null);
|
||||
String filename = (script instanceof ResourceScriptSource resourceScriptSource ?
|
||||
resourceScriptSource.getResource().getFilename() : null);
|
||||
if (filename != null) {
|
||||
return groovyShell.evaluate(script.getScriptAsString(), filename);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -151,17 +151,16 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea
|
|||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (beanFactory instanceof ConfigurableListableBeanFactory) {
|
||||
((ConfigurableListableBeanFactory) beanFactory).ignoreDependencyType(MetaClass.class);
|
||||
if (beanFactory instanceof ConfigurableListableBeanFactory clbf) {
|
||||
clbf.ignoreDependencyType(MetaClass.class);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBeanClassLoader(ClassLoader classLoader) {
|
||||
if (classLoader instanceof GroovyClassLoader &&
|
||||
(this.compilerConfiguration == null ||
|
||||
((GroovyClassLoader) classLoader).hasCompatibleConfiguration(this.compilerConfiguration))) {
|
||||
this.groovyClassLoader = (GroovyClassLoader) classLoader;
|
||||
if (classLoader instanceof GroovyClassLoader gcl && (this.compilerConfiguration == null ||
|
||||
gcl.hasCompatibleConfiguration(this.compilerConfiguration))) {
|
||||
this.groovyClassLoader = gcl;
|
||||
}
|
||||
else {
|
||||
this.groovyClassLoader = buildGroovyClassLoader(classLoader);
|
||||
|
|
@ -318,20 +317,20 @@ public class GroovyScriptFactory implements ScriptFactory, BeanFactoryAware, Bea
|
|||
@Nullable
|
||||
protected Object executeScript(ScriptSource scriptSource, Class<?> scriptClass) throws ScriptCompilationException {
|
||||
try {
|
||||
GroovyObject goo = (GroovyObject) ReflectionUtils.accessibleConstructor(scriptClass).newInstance();
|
||||
GroovyObject groovyObj = (GroovyObject) ReflectionUtils.accessibleConstructor(scriptClass).newInstance();
|
||||
|
||||
if (this.groovyObjectCustomizer != null) {
|
||||
// Allow metaclass and other customization.
|
||||
this.groovyObjectCustomizer.customize(goo);
|
||||
this.groovyObjectCustomizer.customize(groovyObj);
|
||||
}
|
||||
|
||||
if (goo instanceof Script) {
|
||||
if (groovyObj instanceof Script script) {
|
||||
// A Groovy script, probably creating an instance: let's execute it.
|
||||
return ((Script) goo).run();
|
||||
return script.run();
|
||||
}
|
||||
else {
|
||||
// An instance of the scripted class: let's return it as-is.
|
||||
return goo;
|
||||
return groovyObj;
|
||||
}
|
||||
}
|
||||
catch (NoSuchMethodException ex) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -219,11 +219,11 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo
|
|||
|
||||
@Override
|
||||
public void setBeanFactory(BeanFactory beanFactory) {
|
||||
if (!(beanFactory instanceof ConfigurableBeanFactory)) {
|
||||
if (!(beanFactory instanceof ConfigurableBeanFactory cbf)) {
|
||||
throw new IllegalStateException("ScriptFactoryPostProcessor doesn't work with " +
|
||||
"non-ConfigurableBeanFactory: " + beanFactory.getClass());
|
||||
}
|
||||
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
|
||||
this.beanFactory = cbf;
|
||||
|
||||
// Required so that references (up container hierarchies) are correctly resolved.
|
||||
this.scriptBeanFactory.setParentBeanFactory(this.beanFactory);
|
||||
|
|
@ -282,8 +282,8 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo
|
|||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
if (ex instanceof BeanCreationException &&
|
||||
((BeanCreationException) ex).getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
|
||||
if (ex instanceof BeanCreationException bce &&
|
||||
bce.getMostSpecificCause() instanceof BeanCurrentlyInCreationException) {
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("Could not determine scripted object type for bean '" + beanName + "': " +
|
||||
ex.getMessage());
|
||||
|
|
@ -406,11 +406,11 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo
|
|||
protected long resolveRefreshCheckDelay(BeanDefinition beanDefinition) {
|
||||
long refreshCheckDelay = this.defaultRefreshCheckDelay;
|
||||
Object attributeValue = beanDefinition.getAttribute(REFRESH_CHECK_DELAY_ATTRIBUTE);
|
||||
if (attributeValue instanceof Number) {
|
||||
refreshCheckDelay = ((Number) attributeValue).longValue();
|
||||
if (attributeValue instanceof Number number) {
|
||||
refreshCheckDelay = number.longValue();
|
||||
}
|
||||
else if (attributeValue instanceof String) {
|
||||
refreshCheckDelay = Long.parseLong((String) attributeValue);
|
||||
else if (attributeValue instanceof String text) {
|
||||
refreshCheckDelay = Long.parseLong(text);
|
||||
}
|
||||
else if (attributeValue != null) {
|
||||
throw new BeanDefinitionStoreException("Invalid refresh check delay attribute [" +
|
||||
|
|
@ -423,11 +423,11 @@ public class ScriptFactoryPostProcessor implements SmartInstantiationAwareBeanPo
|
|||
protected boolean resolveProxyTargetClass(BeanDefinition beanDefinition) {
|
||||
boolean proxyTargetClass = this.defaultProxyTargetClass;
|
||||
Object attributeValue = beanDefinition.getAttribute(PROXY_TARGET_CLASS_ATTRIBUTE);
|
||||
if (attributeValue instanceof Boolean) {
|
||||
proxyTargetClass = (Boolean) attributeValue;
|
||||
if (attributeValue instanceof Boolean boo) {
|
||||
proxyTargetClass = boo;
|
||||
}
|
||||
else if (attributeValue instanceof String) {
|
||||
proxyTargetClass = Boolean.parseBoolean((String) attributeValue);
|
||||
else if (attributeValue instanceof String text) {
|
||||
proxyTargetClass = Boolean.parseBoolean(text);
|
||||
}
|
||||
else if (attributeValue != null) {
|
||||
throw new BeanDefinitionStoreException("Invalid proxy target class attribute [" +
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2017 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.
|
||||
|
|
@ -173,8 +173,8 @@ public class StandardScriptEvaluator implements ScriptEvaluator, BeanClassLoader
|
|||
if (StringUtils.hasText(this.engineName)) {
|
||||
return StandardScriptUtils.retrieveEngineByName(scriptEngineManager, this.engineName);
|
||||
}
|
||||
else if (script instanceof ResourceScriptSource) {
|
||||
Resource resource = ((ResourceScriptSource) script).getResource();
|
||||
else if (script instanceof ResourceScriptSource resourceScriptSource) {
|
||||
Resource resource = resourceScriptSource.getResource();
|
||||
String extension = StringUtils.getFilenameExtension(resource.getFilename());
|
||||
if (extension == null) {
|
||||
throw new IllegalStateException(
|
||||
|
|
|
|||
|
|
@ -149,7 +149,7 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar
|
|||
if (!ObjectUtils.isEmpty(actualInterfaces)) {
|
||||
boolean adaptationRequired = false;
|
||||
for (Class<?> requestedIfc : actualInterfaces) {
|
||||
if (script instanceof Class ? !requestedIfc.isAssignableFrom((Class<?>) script) :
|
||||
if (script instanceof Class<?> clazz ? !requestedIfc.isAssignableFrom(clazz) :
|
||||
!requestedIfc.isInstance(script)) {
|
||||
adaptationRequired = true;
|
||||
break;
|
||||
|
|
@ -210,8 +210,8 @@ public class StandardScriptFactory implements ScriptFactory, BeanClassLoaderAwar
|
|||
return StandardScriptUtils.retrieveEngineByName(scriptEngineManager, this.scriptEngineName);
|
||||
}
|
||||
|
||||
if (scriptSource instanceof ResourceScriptSource) {
|
||||
String filename = ((ResourceScriptSource) scriptSource).getResource().getFilename();
|
||||
if (scriptSource instanceof ResourceScriptSource resourceScriptSource) {
|
||||
String filename = resourceScriptSource.getResource().getFilename();
|
||||
if (filename != null) {
|
||||
String extension = StringUtils.getFilenameExtension(filename);
|
||||
if (extension != null) {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.
|
||||
|
|
@ -74,7 +74,7 @@ public abstract class StandardScriptUtils {
|
|||
}
|
||||
|
||||
static Bindings getBindings(Map<String, Object> bindings) {
|
||||
return (bindings instanceof Bindings ? (Bindings) bindings : new SimpleBindings(bindings));
|
||||
return (bindings instanceof Bindings b ? b : new SimpleBindings(bindings));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -108,7 +108,7 @@ public class ConcurrentModel extends ConcurrentHashMap<String, Object> implement
|
|||
@Override
|
||||
public ConcurrentModel addAttribute(Object attributeValue) {
|
||||
Assert.notNull(attributeValue, "Model attribute value must not be null");
|
||||
if (attributeValue instanceof Collection && ((Collection<?>) attributeValue).isEmpty()) {
|
||||
if (attributeValue instanceof Collection<?> collection && collection.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return addAttribute(Conventions.getVariableName(attributeValue), attributeValue);
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
@ -88,7 +88,7 @@ public class ModelMap extends LinkedHashMap<String, Object> {
|
|||
*/
|
||||
public ModelMap addAttribute(Object attributeValue) {
|
||||
Assert.notNull(attributeValue, "Model object must not be null");
|
||||
if (attributeValue instanceof Collection && ((Collection<?>) attributeValue).isEmpty()) {
|
||||
if (attributeValue instanceof Collection<?> collection && collection.isEmpty()) {
|
||||
return this;
|
||||
}
|
||||
return addAttribute(Conventions.getVariableName(attributeValue), attributeValue);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2022 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.
|
||||
|
|
@ -59,11 +59,11 @@ public abstract class UiApplicationContextUtils {
|
|||
if (context.containsLocalBean(THEME_SOURCE_BEAN_NAME)) {
|
||||
ThemeSource themeSource = context.getBean(THEME_SOURCE_BEAN_NAME, ThemeSource.class);
|
||||
// Make ThemeSource aware of parent ThemeSource.
|
||||
if (context.getParent() instanceof ThemeSource && themeSource instanceof HierarchicalThemeSource hts) {
|
||||
if (context.getParent() instanceof ThemeSource pts && themeSource instanceof HierarchicalThemeSource hts) {
|
||||
if (hts.getParentThemeSource() == null) {
|
||||
// Only set parent context as parent ThemeSource if no parent ThemeSource
|
||||
// registered already.
|
||||
hts.setParentThemeSource((ThemeSource) context.getParent());
|
||||
hts.setParentThemeSource(pts);
|
||||
}
|
||||
}
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
@ -75,9 +75,9 @@ public abstract class UiApplicationContextUtils {
|
|||
// Use default ThemeSource to be able to accept getTheme calls, either
|
||||
// delegating to parent context's default or to local ResourceBundleThemeSource.
|
||||
HierarchicalThemeSource themeSource = null;
|
||||
if (context.getParent() instanceof ThemeSource) {
|
||||
if (context.getParent() instanceof ThemeSource pts) {
|
||||
themeSource = new DelegatingThemeSource();
|
||||
themeSource.setParentThemeSource((ThemeSource) context.getParent());
|
||||
themeSource.setParentThemeSource(pts);
|
||||
}
|
||||
else {
|
||||
themeSource = new ResourceBundleThemeSource();
|
||||
|
|
|
|||
Loading…
Reference in New Issue