diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java index 52b73493b80..eba32e8aa71 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.java @@ -186,11 +186,10 @@ public class DevToolsDataSourceAutoConfiguration { return ConditionOutcome.noMatch(message.didNotFind("a single DataSourceProperties bean").atAll()); } BeanDefinition dataSourceDefinition = context.getRegistry().getBeanDefinition(dataSourceBeanNames[0]); - if (dataSourceDefinition instanceof AnnotatedBeanDefinition - && ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata() != null - && ((AnnotatedBeanDefinition) dataSourceDefinition).getFactoryMethodMetadata() - .getDeclaringClassName().startsWith(DataSourceAutoConfiguration.class.getPackage().getName() - + ".DataSourceConfiguration$")) { + if (dataSourceDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition + && annotatedBeanDefinition.getFactoryMethodMetadata() != null + && annotatedBeanDefinition.getFactoryMethodMetadata().getDeclaringClassName().startsWith( + DataSourceAutoConfiguration.class.getPackage().getName() + ".DataSourceConfiguration$")) { return ConditionOutcome.match(message.foundExactly("auto-configured DataSource")); } return ConditionOutcome.noMatch(message.didNotFind("an auto-configured DataSource").atAll()); diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfiguration.java index c59b9fc2bf8..ac569f100f3 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/DevToolsR2dbcAutoConfiguration.java @@ -118,8 +118,8 @@ public class DevToolsR2dbcAutoConfiguration { return ConditionOutcome.noMatch(message.didNotFind("a single ConnectionFactory bean").atAll()); } BeanDefinition beanDefinition = context.getRegistry().getBeanDefinition(beanNames[0]); - if (beanDefinition instanceof AnnotatedBeanDefinition - && isAutoConfigured((AnnotatedBeanDefinition) beanDefinition)) { + if (beanDefinition instanceof AnnotatedBeanDefinition annotatedBeanDefinition + && isAutoConfigured(annotatedBeanDefinition)) { return ConditionOutcome.match(message.foundExactly("auto-configured ConnectionFactory")); } return ConditionOutcome.noMatch(message.didNotFind("an auto-configured ConnectionFactory").atAll()); diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java index 5164d09dd34..4f0d2fde9bb 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/LocalDevToolsAutoConfiguration.java @@ -191,8 +191,8 @@ public class LocalDevToolsAutoConfiguration { @Override public void onApplicationEvent(ApplicationEvent event) { - if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent - && !((ClassPathChangedEvent) event).isRestartRequired())) { + if (event instanceof ContextRefreshedEvent || (event instanceof ClassPathChangedEvent classPathChangedEvent + && !classPathChangedEvent.isRestartRequired())) { this.liveReloadServer.triggerReload(); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrar.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrar.java index 3ed035657e1..704eef54ac3 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrar.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/ConfigurationPropertiesBeanRegistrar.java @@ -71,8 +71,8 @@ final class ConfigurationPropertiesBeanRegistrar { } private boolean containsBeanDefinition(BeanFactory beanFactory, String name) { - if (beanFactory instanceof ListableBeanFactory - && ((ListableBeanFactory) beanFactory).containsBeanDefinition(name)) { + if (beanFactory instanceof ListableBeanFactory listableBeanFactory + && listableBeanFactory.containsBeanDefinition(name)) { return true; } if (beanFactory instanceof HierarchicalBeanFactory hierarchicalBeanFactory) { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java index 96a97c225a6..cbf2668856c 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/IndexedElementsBinder.java @@ -89,7 +89,7 @@ abstract class IndexedElementsBinder extends AggregateBinder { private void bindValue(Bindable target, Collection collection, ResolvableType aggregateType, ResolvableType elementType, Object value) { - if (value == null || value instanceof CharSequence && ((CharSequence) value).length() == 0) { + if (value == null || (value instanceof CharSequence charSequence && charSequence.isEmpty())) { return; } Object aggregate = convert(value, aggregateType, target.getAnnotations()); diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java index 472368a487d..a4dc11746a7 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/OriginTrackedYamlLoader.java @@ -97,7 +97,7 @@ class OriginTrackedYamlLoader extends YamlProcessor { @Override public Object getData() throws NoSuchElementException { Object data = super.getData(); - if (data instanceof CharSequence && ((CharSequence) data).length() == 0) { + if (data instanceof CharSequence charSequence && charSequence.isEmpty()) { return null; } return data; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java index ba10642b13b..0e1189be04a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/env/SpringApplicationJsonEnvironmentPostProcessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 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. @@ -213,8 +213,8 @@ public class SpringApplicationJsonEnvironmentPostProcessor implements Environmen static JsonPropertyValue get(PropertySource propertySource) { for (String candidate : CANDIDATES) { Object value = propertySource.getProperty(candidate); - if (value instanceof String && StringUtils.hasLength((String) value)) { - return new JsonPropertyValue(propertySource, candidate, (String) value); + if (value instanceof String string && StringUtils.hasLength(string)) { + return new JsonPropertyValue(propertySource, candidate, string); } } return null; diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java index 986bf5d3d0d..dcd825836e0 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/ServletComponentRegisteringPostProcessor.java @@ -81,8 +81,8 @@ class ServletComponentRegisteringPostProcessor implements BeanFactoryPostProcess } private boolean isRunningInEmbeddedWebServer() { - return this.applicationContext instanceof WebApplicationContext - && ((WebApplicationContext) this.applicationContext).getServletContext() == null; + return this.applicationContext instanceof WebApplicationContext webApplicationContext + && webApplicationContext.getServletContext() == null; } private ClassPathScanningCandidateComponentProvider createComponentProvider() { diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java index 4b9f7ca1932..a9c49f04700 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/web/servlet/server/StaticResourceJars.java @@ -107,7 +107,7 @@ class StaticResourceJars { } private void addUrlConnection(List urls, URL url, URLConnection connection) { - if (connection instanceof JarURLConnection && isResourcesJar((JarURLConnection) connection)) { + if (connection instanceof JarURLConnection jarURLConnection && isResourcesJar(jarURLConnection)) { urls.add(url); } }