Skip to content

Commit a892ce8

Browse files
aooohansbrannen
authored andcommitted
Polishing regarding JDK baseline upgrade
Closes gh-28440
1 parent 5c5c89e commit a892ce8

File tree

9 files changed

+21
-26
lines changed

9 files changed

+21
-26
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/autoproxy/AspectJAwareAdvisorAutoProxyCreator.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,12 @@ public String toString() {
143143
Advice advice = this.advisor.getAdvice();
144144
StringBuilder sb = new StringBuilder(ClassUtils.getShortName(advice.getClass()));
145145
boolean appended = false;
146-
if (this.advisor instanceof Ordered) {
147-
sb.append(": order = ").append(((Ordered) this.advisor).getOrder());
146+
if (this.advisor instanceof Ordered ordered) {
147+
sb.append(": order = ").append(ordered.getOrder());
148148
appended = true;
149149
}
150-
if (advice instanceof AbstractAspectJAdvice) {
150+
if (advice instanceof AbstractAspectJAdvice ajAdvice) {
151151
sb.append(!appended ? ": " : ", ");
152-
AbstractAspectJAdvice ajAdvice = (AbstractAspectJAdvice) advice;
153152
sb.append("aspect name = ");
154153
sb.append(ajAdvice.getAspectName());
155154
sb.append(", declaration order = ");

spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ private TargetSource freshTargetSource() {
556556
logger.debug("Refreshing target with name '" + this.targetName + "'");
557557
}
558558
Object target = this.beanFactory.getBean(this.targetName);
559-
return (target instanceof TargetSource ? (TargetSource) target : new SingletonTargetSource(target));
559+
return (target instanceof TargetSource targetSource ? targetSource : new SingletonTargetSource(target));
560560
}
561561
}
562562

spring-aop/src/main/java/org/springframework/aop/scope/ScopedProxyUtils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public static BeanDefinitionHolder createScopedProxy(BeanDefinitionHolder defini
8080
// Copy autowire settings from original bean definition.
8181
proxyDefinition.setAutowireCandidate(targetDefinition.isAutowireCandidate());
8282
proxyDefinition.setPrimary(targetDefinition.isPrimary());
83-
if (targetDefinition instanceof AbstractBeanDefinition) {
84-
proxyDefinition.copyQualifiersFrom((AbstractBeanDefinition) targetDefinition);
83+
if (targetDefinition instanceof AbstractBeanDefinition abd) {
84+
proxyDefinition.copyQualifiersFrom(abd);
8585
}
8686

8787
// The target bean should be ignored in favor of the scoped proxy.

spring-aop/src/main/java/org/springframework/aop/support/AbstractPointcutAdvisor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public int getOrder() {
5252
return this.order;
5353
}
5454
Advice advice = getAdvice();
55-
if (advice instanceof Ordered) {
56-
return ((Ordered) advice).getOrder();
55+
if (advice instanceof Ordered ordered) {
56+
return ordered.getOrder();
5757
}
5858
return Ordered.LOWEST_PRECEDENCE;
5959
}

spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,7 +841,7 @@ private AbstractNestablePropertyAccessor getNestedPropertyAccessor(String nested
841841
PropertyTokenHolder tokens = getPropertyNameTokens(nestedProperty);
842842
String canonicalName = tokens.canonicalName;
843843
Object value = getPropertyValue(tokens);
844-
if (value == null || (value instanceof Optional && !((Optional<?>) value).isPresent())) {
844+
if (value == null || (value instanceof Optional<?> optional && optional.isEmpty()) {
845845
if (isAutoGrowNestedPaths()) {
846846
value = setDefaultValue(tokens);
847847
}

spring-beans/src/main/java/org/springframework/beans/factory/BeanFactoryUtils.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,8 @@ public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lb
162162
Assert.notNull(lbf, "ListableBeanFactory must not be null");
163163
String[] result = lbf.getBeanNamesForType(type);
164164
if (lbf instanceof HierarchicalBeanFactory hbf) {
165-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
166-
String[] parentResult = beanNamesForTypeIncludingAncestors(
167-
(ListableBeanFactory) hbf.getParentBeanFactory(), type);
165+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
166+
String[] parentResult = beanNamesForTypeIncludingAncestors(pbf, type);
168167
result = mergeNamesWithParent(result, parentResult, hbf);
169168
}
170169
}
@@ -225,9 +224,8 @@ public static String[] beanNamesForTypeIncludingAncestors(ListableBeanFactory lb
225224
Assert.notNull(lbf, "ListableBeanFactory must not be null");
226225
String[] result = lbf.getBeanNamesForType(type);
227226
if (lbf instanceof HierarchicalBeanFactory hbf) {
228-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
229-
String[] parentResult = beanNamesForTypeIncludingAncestors(
230-
(ListableBeanFactory) hbf.getParentBeanFactory(), type);
227+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
228+
String[] parentResult = beanNamesForTypeIncludingAncestors(pbf, type);
231229
result = mergeNamesWithParent(result, parentResult, hbf);
232230
}
233231
}
@@ -371,9 +369,8 @@ public static <T> Map<String, T> beansOfTypeIncludingAncestors(
371369
Map<String, T> result = new LinkedHashMap<>(4);
372370
result.putAll(lbf.getBeansOfType(type, includeNonSingletons, allowEagerInit));
373371
if (lbf instanceof HierarchicalBeanFactory hbf) {
374-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
375-
Map<String, T> parentResult = beansOfTypeIncludingAncestors(
376-
(ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit);
372+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
373+
Map<String, T> parentResult = beansOfTypeIncludingAncestors(pbf, type, includeNonSingletons, allowEagerInit);
377374
parentResult.forEach((beanName, beanInstance) -> {
378375
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
379376
result.put(beanName, beanInstance);

spring-messaging/src/main/java/org/springframework/messaging/handler/HandlerMethod.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,8 @@ public HandlerMethod getResolvedFromHandlerMethod() {
286286
*/
287287
public HandlerMethod createWithResolvedBean() {
288288
Object handler = this.bean;
289-
if (this.bean instanceof String) {
289+
if (this.bean instanceof String beanName) {
290290
Assert.state(this.beanFactory != null, "Cannot resolve bean name without BeanFactory");
291-
String beanName = (String) this.bean;
292291
handler = this.beanFactory.getBean(beanName);
293292
}
294293
return new HandlerMethod(this, handler);

spring-web/src/testFixtures/java/org/springframework/web/testfixture/servlet/MockHttpServletResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ private boolean setSpecialHeader(String name, Object value, boolean replaceHeade
692692
return true;
693693
}
694694
else if (HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(name)) {
695-
setContentLength(value instanceof Number ? ((Number) value).intValue() :
695+
setContentLength(value instanceof Number number ? number.intValue() :
696696
Integer.parseInt(value.toString()));
697697
return true;
698698
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc
549549
*/
550550
@Override
551551
public void setBeanFactory(BeanFactory beanFactory) {
552-
if (beanFactory instanceof ConfigurableBeanFactory) {
553-
this.beanFactory = (ConfigurableBeanFactory) beanFactory;
552+
if (beanFactory instanceof ConfigurableBeanFactory cbf) {
553+
this.beanFactory = cbf;
554554
}
555555
}
556556

@@ -1010,8 +1010,8 @@ private ModelAndView getModelAndView(ModelAndViewContainer mavContainer,
10101010
if (!mavContainer.isViewReference()) {
10111011
mav.setView((View) mavContainer.getView());
10121012
}
1013-
if (model instanceof RedirectAttributes) {
1014-
Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
1013+
if (model instanceof RedirectAttributes redirectAttributes) {
1014+
Map<String, ?> flashAttributes = redirectAttributes.getFlashAttributes();
10151015
HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
10161016
if (request != null) {
10171017
RequestContextUtils.getOutputFlashMap(request).putAll(flashAttributes);

0 commit comments

Comments
 (0)