Skip to content

Commit eb50a6f

Browse files
committed
Further polishing regarding JDK baseline upgrade
See gh-28440
1 parent a892ce8 commit eb50a6f

File tree

11 files changed

+45
-51
lines changed

11 files changed

+45
-51
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -100,8 +100,8 @@ protected boolean shouldSkip(Class<?> beanClass, String beanName) {
100100
// TODO: Consider optimization by caching the list of the aspect names
101101
List<Advisor> candidateAdvisors = findCandidateAdvisors();
102102
for (Advisor advisor : candidateAdvisors) {
103-
if (advisor instanceof AspectJPointcutAdvisor &&
104-
((AspectJPointcutAdvisor) advisor).getAspectName().equals(beanName)) {
103+
if (advisor instanceof AspectJPointcutAdvisor pointcutAdvisor &&
104+
pointcutAdvisor.getAspectName().equals(beanName)) {
105105
return true;
106106
}
107107
}

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -436,12 +436,11 @@ private synchronized void initializeAdvisorChain() throws AopConfigException, Be
436436
// Materialize interceptor chain from bean names.
437437
for (String name : this.interceptorNames) {
438438
if (name.endsWith(GLOBAL_SUFFIX)) {
439-
if (!(this.beanFactory instanceof ListableBeanFactory)) {
439+
if (!(this.beanFactory instanceof ListableBeanFactory lbf)) {
440440
throw new AopConfigException(
441441
"Can only use global advisors or interceptors with a ListableBeanFactory");
442442
}
443-
addGlobalAdvisors((ListableBeanFactory) this.beanFactory,
444-
name.substring(0, name.length() - GLOBAL_SUFFIX.length()));
443+
addGlobalAdvisors(lbf, name.substring(0, name.length() - GLOBAL_SUFFIX.length()));
445444
}
446445

447446
else {
@@ -475,16 +474,16 @@ private List<Advisor> freshAdvisorChain() {
475474
Advisor[] advisors = getAdvisors();
476475
List<Advisor> freshAdvisors = new ArrayList<>(advisors.length);
477476
for (Advisor advisor : advisors) {
478-
if (advisor instanceof PrototypePlaceholderAdvisor pa) {
477+
if (advisor instanceof PrototypePlaceholderAdvisor ppa) {
479478
if (logger.isDebugEnabled()) {
480-
logger.debug("Refreshing bean named '" + pa.getBeanName() + "'");
479+
logger.debug("Refreshing bean named '" + ppa.getBeanName() + "'");
481480
}
482481
// Replace the placeholder with a fresh prototype instance resulting from a getBean lookup
483482
if (this.beanFactory == null) {
484483
throw new IllegalStateException("No BeanFactory available anymore (probably due to " +
485-
"serialization) - cannot resolve prototype advisor '" + pa.getBeanName() + "'");
484+
"serialization) - cannot resolve prototype advisor '" + ppa.getBeanName() + "'");
486485
}
487-
Object bean = this.beanFactory.getBean(pa.getBeanName());
486+
Object bean = this.beanFactory.getBean(ppa.getBeanName());
488487
Advisor refreshedAdvisor = namedBeanToAdvisor(bean);
489488
freshAdvisors.add(refreshedAdvisor);
490489
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -60,6 +60,7 @@
6060
* @author Stephane Nicoll
6161
* @author Rod Johnson
6262
* @author Rob Harrop
63+
* @author Sam Brannen
6364
* @since 4.2
6465
* @see #registerCustomEditor
6566
* @see #setPropertyValues
@@ -279,7 +280,7 @@ protected void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv) th
279280
}
280281
}
281282

282-
@SuppressWarnings("unchecked")
283+
@SuppressWarnings({"unchecked", "rawtypes"})
283284
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
284285
Object propValue = getPropertyHoldingValue(tokens);
285286
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
@@ -318,9 +319,8 @@ private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv)
318319
}
319320
}
320321

321-
else if (propValue instanceof List) {
322+
else if (propValue instanceof List list) {
322323
Class<?> requiredType = ph.getCollectionType(tokens.keys.length);
323-
List<Object> list = (List<Object>) propValue;
324324
int index = Integer.parseInt(lastKey);
325325
Object oldValue = null;
326326
if (isExtractOldValueForEditor() && index < list.size()) {
@@ -354,10 +354,9 @@ else if (propValue instanceof List) {
354354
}
355355
}
356356

357-
else if (propValue instanceof Map) {
357+
else if (propValue instanceof Map map) {
358358
Class<?> mapKeyType = ph.getMapKeyType(tokens.keys.length);
359359
Class<?> mapValueType = ph.getMapValueType(tokens.keys.length);
360-
Map<Object, Object> map = (Map<Object, Object>) propValue;
361360
// IMPORTANT: Do not pass full property name in here - property editors
362361
// must not kick in for map keys but rather only for map values.
363362
TypeDescriptor typeDescriptor = TypeDescriptor.valueOf(mapKeyType);
@@ -446,8 +445,8 @@ private void processLocalProperty(PropertyTokenHolder tokens, PropertyValue pv)
446445
oldValue = ph.getValue();
447446
}
448447
catch (Exception ex) {
449-
if (ex instanceof PrivilegedActionException) {
450-
ex = ((PrivilegedActionException) ex).getException();
448+
if (ex instanceof PrivilegedActionException pae) {
449+
ex = pae.getException();
451450
}
452451
if (logger.isDebugEnabled()) {
453452
logger.debug("Could not read previous value of property '" +
@@ -617,7 +616,7 @@ public Object getPropertyValue(String propertyName) throws BeansException {
617616
return nestedPa.getPropertyValue(tokens);
618617
}
619618

620-
@SuppressWarnings("unchecked")
619+
@SuppressWarnings({"unchecked", "rawtypes"})
621620
@Nullable
622621
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
623622
String propertyName = tokens.canonicalName;
@@ -653,15 +652,13 @@ else if (value.getClass().isArray()) {
653652
value = growArrayIfNecessary(value, index, indexedPropertyName.toString());
654653
value = Array.get(value, index);
655654
}
656-
else if (value instanceof List) {
655+
else if (value instanceof List list) {
657656
int index = Integer.parseInt(key);
658-
List<Object> list = (List<Object>) value;
659657
growCollectionIfNecessary(list, index, indexedPropertyName.toString(), ph, i + 1);
660658
value = list.get(index);
661659
}
662-
else if (value instanceof Set) {
660+
else if (value instanceof Set set) {
663661
// Apply index to Iterator in case of a Set.
664-
Set<Object> set = (Set<Object>) value;
665662
int index = Integer.parseInt(key);
666663
if (index < 0 || index >= set.size()) {
667664
throw new InvalidPropertyException(getRootClass(), this.nestedPath + propertyName,
@@ -677,8 +674,7 @@ else if (value instanceof Set) {
677674
}
678675
}
679676
}
680-
else if (value instanceof Map) {
681-
Map<Object, Object> map = (Map<Object, Object>) value;
677+
else if (value instanceof Map map) {
682678
Class<?> mapKeyType = ph.getResolvableType().getNested(i + 1).asMap().resolveGeneric(0);
683679
// IMPORTANT: Do not pass full property name in here - property editors
684680
// must not kick in for map keys but rather only for map values.
@@ -841,7 +837,7 @@ private AbstractNestablePropertyAccessor getNestedPropertyAccessor(String nested
841837
PropertyTokenHolder tokens = getPropertyNameTokens(nestedProperty);
842838
String canonicalName = tokens.canonicalName;
843839
Object value = getPropertyValue(tokens);
844-
if (value == null || (value instanceof Optional<?> optional && optional.isEmpty()) {
840+
if (value == null || (value instanceof Optional<?> optional && optional.isEmpty())) {
845841
if (isAutoGrowNestedPaths()) {
846842
value = setDefaultValue(tokens);
847843
}

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -198,9 +198,9 @@ public static String[] beanNamesForTypeIncludingAncestors(
198198
Assert.notNull(lbf, "ListableBeanFactory must not be null");
199199
String[] result = lbf.getBeanNamesForType(type, includeNonSingletons, allowEagerInit);
200200
if (lbf instanceof HierarchicalBeanFactory hbf) {
201-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
201+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
202202
String[] parentResult = beanNamesForTypeIncludingAncestors(
203-
(ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit);
203+
pbf, type, includeNonSingletons, allowEagerInit);
204204
result = mergeNamesWithParent(result, parentResult, hbf);
205205
}
206206
}
@@ -259,9 +259,9 @@ public static String[] beanNamesForTypeIncludingAncestors(
259259
Assert.notNull(lbf, "ListableBeanFactory must not be null");
260260
String[] result = lbf.getBeanNamesForType(type, includeNonSingletons, allowEagerInit);
261261
if (lbf instanceof HierarchicalBeanFactory hbf) {
262-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
262+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
263263
String[] parentResult = beanNamesForTypeIncludingAncestors(
264-
(ListableBeanFactory) hbf.getParentBeanFactory(), type, includeNonSingletons, allowEagerInit);
264+
pbf, type, includeNonSingletons, allowEagerInit);
265265
result = mergeNamesWithParent(result, parentResult, hbf);
266266
}
267267
}
@@ -284,9 +284,8 @@ public static String[] beanNamesForAnnotationIncludingAncestors(
284284
Assert.notNull(lbf, "ListableBeanFactory must not be null");
285285
String[] result = lbf.getBeanNamesForAnnotation(annotationType);
286286
if (lbf instanceof HierarchicalBeanFactory hbf) {
287-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
288-
String[] parentResult = beanNamesForAnnotationIncludingAncestors(
289-
(ListableBeanFactory) hbf.getParentBeanFactory(), annotationType);
287+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
288+
String[] parentResult = beanNamesForAnnotationIncludingAncestors(pbf, annotationType);
290289
result = mergeNamesWithParent(result, parentResult, hbf);
291290
}
292291
}
@@ -321,9 +320,8 @@ public static <T> Map<String, T> beansOfTypeIncludingAncestors(ListableBeanFacto
321320
Map<String, T> result = new LinkedHashMap<>(4);
322321
result.putAll(lbf.getBeansOfType(type));
323322
if (lbf instanceof HierarchicalBeanFactory hbf) {
324-
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory) {
325-
Map<String, T> parentResult = beansOfTypeIncludingAncestors(
326-
(ListableBeanFactory) hbf.getParentBeanFactory(), type);
323+
if (hbf.getParentBeanFactory() instanceof ListableBeanFactory pbf) {
324+
Map<String, T> parentResult = beansOfTypeIncludingAncestors(pbf, type);
327325
parentResult.forEach((beanName, beanInstance) -> {
328326
if (!result.containsKey(beanName) && !hbf.containsLocalBean(beanName)) {
329327
result.put(beanName, beanInstance);

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -423,7 +423,7 @@ private String getCookieHeader(Cookie cookie) {
423423
buf.append("; Domain=").append(cookie.getDomain());
424424
}
425425
int maxAge = cookie.getMaxAge();
426-
ZonedDateTime expires = (cookie instanceof MockCookie ? ((MockCookie) cookie).getExpires() : null);
426+
ZonedDateTime expires = (cookie instanceof MockCookie mockCookie? mockCookie.getExpires() : null);
427427
if (maxAge >= 0) {
428428
buf.append("; Max-Age=").append(maxAge);
429429
buf.append("; Expires=");
@@ -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-web/src/main/java/org/springframework/http/HttpMethod.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -177,8 +177,8 @@ public boolean equals(Object o) {
177177
if (this == o) {
178178
return true;
179179
}
180-
else if (o instanceof HttpMethod other) {
181-
return this.name.equals(other.name);
180+
else if (o instanceof HttpMethod otherMethod) {
181+
return this.name.equals(otherMethod.name);
182182
}
183183
return false;
184184
}
@@ -187,4 +187,5 @@ else if (o instanceof HttpMethod other) {
187187
public String toString() {
188188
return this.name;
189189
}
190+
190191
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -423,7 +423,7 @@ private String getCookieHeader(Cookie cookie) {
423423
buf.append("; Domain=").append(cookie.getDomain());
424424
}
425425
int maxAge = cookie.getMaxAge();
426-
ZonedDateTime expires = (cookie instanceof MockCookie ? ((MockCookie) cookie).getExpires() : null);
426+
ZonedDateTime expires = (cookie instanceof MockCookie mockCookie? mockCookie.getExpires() : null);
427427
if (maxAge >= 0) {
428428
buf.append("; Max-Age=").append(maxAge);
429429
buf.append("; Expires=");

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public ReactiveAdapterRegistry getReactiveAdapterRegistry() {
149149
*/
150150
@Override
151151
public void setApplicationContext(ApplicationContext applicationContext) {
152-
if (applicationContext instanceof ConfigurableApplicationContext) {
153-
this.applicationContext = (ConfigurableApplicationContext) applicationContext;
152+
if (applicationContext instanceof ConfigurableApplicationContext cac) {
153+
this.applicationContext = cac;
154154
}
155155
}
156156

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)