Skip to content

Commit 5db04da

Browse files
dreis2211wilkinsona
authored andcommitted
Use pattern matching for instanceof where appropriate
See spring-projectsgh-31475
1 parent a7b98e7 commit 5db04da

File tree

278 files changed

+1049
-1126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+1049
-1126
lines changed

buildSrc/src/main/java/org/springframework/boot/build/AsciidoctorConventions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,10 @@ private void configureAsciidoctorTask(Project project, AbstractAsciidoctorTask a
120120
configureOptions(asciidoctorTask);
121121
asciidoctorTask.baseDirFollowsSourceDir();
122122
createSyncDocumentationSourceTask(project, asciidoctorTask);
123-
if (asciidoctorTask instanceof AsciidoctorTask) {
124-
boolean pdf = asciidoctorTask.getName().toLowerCase().contains("pdf");
123+
if (asciidoctorTask instanceof AsciidoctorTask task) {
124+
boolean pdf = task.getName().toLowerCase().contains("pdf");
125125
String backend = (!pdf) ? "spring-html" : "spring-pdf";
126-
((AsciidoctorTask) asciidoctorTask).outputOptions((outputOptions) -> outputOptions.backends(backend));
126+
task.outputOptions((outputOptions) -> outputOptions.backends(backend));
127127
}
128128
}
129129

buildSrc/src/main/java/org/springframework/boot/build/bom/BomExtension.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public GroupHandler(String id) {
300300

301301
public void setModules(List<Object> modules) {
302302
this.modules = modules.stream()
303-
.map((input) -> (input instanceof Module) ? (Module) input : new Module((String) input))
303+
.map((input) -> (input instanceof Module module) ? module : new Module((String) input))
304304
.collect(Collectors.toList());
305305
}
306306

@@ -315,9 +315,8 @@ public void setPlugins(List<String> plugins) {
315315
public Object methodMissing(String name, Object args) {
316316
if (args instanceof Object[] && ((Object[]) args).length == 1) {
317317
Object arg = ((Object[]) args)[0];
318-
if (arg instanceof Closure) {
318+
if (arg instanceof Closure closure) {
319319
ModuleHandler moduleHandler = new ModuleHandler();
320-
Closure<?> closure = (Closure<?>) arg;
321320
closure.setResolveStrategy(Closure.DELEGATE_FIRST);
322321
closure.setDelegate(moduleHandler);
323322
closure.call(moduleHandler);

buildSrc/src/main/java/org/springframework/boot/build/bom/BomPlugin.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,8 @@ private Node findOrCreateNode(Node parent, String... path) {
255255

256256
private Node findChild(Node parent, String name) {
257257
for (Object child : parent.children()) {
258-
if (child instanceof Node) {
259-
Node node = (Node) child;
260-
if ((node.name() instanceof QName) && name.equals(((QName) node.name()).getLocalPart())) {
258+
if (child instanceof Node node) {
259+
if ((node.name() instanceof QName qname) && name.equals(qname.getLocalPart())) {
261260
return node;
262261
}
263262
if (name.equals(node.name())) {
@@ -276,9 +275,8 @@ private List<Node> findChildren(Node parent, String name) {
276275
}
277276

278277
private boolean isNodeWithName(Object candidate, String name) {
279-
if (candidate instanceof Node) {
280-
Node node = (Node) candidate;
281-
if ((node.name() instanceof QName) && name.equals(((QName) node.name()).getLocalPart())) {
278+
if (candidate instanceof Node node) {
279+
if ((node.name() instanceof QName qname) && name.equals(qname.getLocalPart())) {
282280
return true;
283281
}
284282
if (name.equals(node.name())) {

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/github/StandardGitHubRepository.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ public int openIssue(String title, String body, List<String> labels, Milestone m
6363
return (Integer) response.getBody().get("number");
6464
}
6565
catch (RestClientException ex) {
66-
if (ex instanceof Forbidden) {
67-
System.out.println("Received 403 response with headers " + ((Forbidden) ex).getResponseHeaders());
66+
if (ex instanceof Forbidden forbidden) {
67+
System.out.println("Received 403 response with headers " + forbidden.getResponseHeaders());
6868
}
6969
throw ex;
7070
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/AbstractDependencyVersion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-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.
@@ -33,8 +33,8 @@ protected AbstractDependencyVersion(ComparableVersion comparableVersion) {
3333

3434
@Override
3535
public int compareTo(DependencyVersion other) {
36-
ComparableVersion otherComparable = (other instanceof AbstractDependencyVersion)
37-
? ((AbstractDependencyVersion) other).comparableVersion : new ComparableVersion(other.toString());
36+
ComparableVersion otherComparable = (other instanceof AbstractDependencyVersion otherVersion)
37+
? otherVersion.comparableVersion : new ComparableVersion(other.toString());
3838
return this.comparableVersion.compareTo(otherComparable);
3939
}
4040

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ArtifactVersionDependencyVersion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-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.
@@ -83,8 +83,8 @@ public String toString() {
8383
protected Optional<ArtifactVersionDependencyVersion> extractArtifactVersionDependencyVersion(
8484
DependencyVersion other) {
8585
ArtifactVersionDependencyVersion artifactVersion = null;
86-
if (other instanceof ArtifactVersionDependencyVersion) {
87-
artifactVersion = (ArtifactVersionDependencyVersion) other;
86+
if (other instanceof ArtifactVersionDependencyVersion otherVersion) {
87+
artifactVersion = otherVersion;
8888
}
8989
return Optional.ofNullable(artifactVersion);
9090
}

buildSrc/src/main/java/org/springframework/boot/build/bom/bomr/version/ReleaseTrainDependencyVersion.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -47,10 +47,9 @@ private ReleaseTrainDependencyVersion(String releaseTrain, String type, int vers
4747

4848
@Override
4949
public int compareTo(DependencyVersion other) {
50-
if (!(other instanceof ReleaseTrainDependencyVersion)) {
50+
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
5151
return -1;
5252
}
53-
ReleaseTrainDependencyVersion otherReleaseTrain = (ReleaseTrainDependencyVersion) other;
5453
int comparison = this.releaseTrain.compareTo(otherReleaseTrain.releaseTrain);
5554
if (comparison != 0) {
5655
return comparison;
@@ -67,10 +66,9 @@ public boolean isNewerThan(DependencyVersion other) {
6766
if (other instanceof CalendarVersionDependencyVersion) {
6867
return false;
6968
}
70-
if (!(other instanceof ReleaseTrainDependencyVersion)) {
69+
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
7170
return true;
7271
}
73-
ReleaseTrainDependencyVersion otherReleaseTrain = (ReleaseTrainDependencyVersion) other;
7472
return otherReleaseTrain.compareTo(this) < 0;
7573
}
7674

@@ -84,10 +82,9 @@ public boolean isSameMinorAndNewerThan(DependencyVersion other) {
8482
if (other instanceof CalendarVersionDependencyVersion) {
8583
return false;
8684
}
87-
if (!(other instanceof ReleaseTrainDependencyVersion)) {
85+
if (!(other instanceof ReleaseTrainDependencyVersion otherReleaseTrain)) {
8886
return true;
8987
}
90-
ReleaseTrainDependencyVersion otherReleaseTrain = (ReleaseTrainDependencyVersion) other;
9188
return otherReleaseTrain.releaseTrain.equals(this.releaseTrain) && isNewerThan(other);
9289
}
9390

buildSrc/src/main/java/org/springframework/boot/build/classpath/CheckClasspathForUnnecessaryExclusions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -79,8 +79,8 @@ public void setClasspath(Configuration classpath) {
7979
}
8080

8181
private void processDependency(Dependency dependency) {
82-
if (dependency instanceof ModuleDependency) {
83-
processDependency((ModuleDependency) dependency);
82+
if (dependency instanceof ModuleDependency moduleDependency) {
83+
processDependency(moduleDependency);
8484
}
8585
}
8686

buildSrc/src/main/java/org/springframework/boot/build/mavenplugin/MavenPluginPlugin.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,9 +373,7 @@ public Configuration getRuntimeClasspath() {
373373
@TaskAction
374374
public void createRepository() {
375375
for (ResolvedArtifactResult result : this.runtimeClasspath.getIncoming().getArtifacts()) {
376-
if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier) {
377-
ModuleComponentIdentifier identifier = (ModuleComponentIdentifier) result.getId()
378-
.getComponentIdentifier();
376+
if (result.getId().getComponentIdentifier() instanceof ModuleComponentIdentifier identifier) {
379377
String fileName = result.getFile().getName()
380378
.replace(identifier.getVersion() + "-" + identifier.getVersion(), identifier.getVersion());
381379
File repositoryLocation = this.outputDirectory.dir(identifier.getGroup().replace('.', '/') + "/"

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/CloudFoundrySecurityInterceptor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-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.
@@ -93,8 +93,7 @@ private Mono<Void> check(ServerWebExchange exchange, String id) {
9393
}
9494

9595
private Mono<SecurityResponse> getErrorResponse(Throwable throwable) {
96-
if (throwable instanceof CloudFoundryAuthorizationException) {
97-
CloudFoundryAuthorizationException cfException = (CloudFoundryAuthorizationException) throwable;
96+
if (throwable instanceof CloudFoundryAuthorizationException cfException) {
9897
return Mono.just(new SecurityResponse(cfException.getStatusCode(),
9998
"{\"security_error\":\"" + cfException.getMessage() + "\"}"));
10099
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundryActuatorAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ static class WebFilterChainPostProcessor implements BeanPostProcessor {
164164

165165
@Override
166166
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
167-
if (bean instanceof WebFilterChainProxy) {
168-
return postProcess((WebFilterChainProxy) bean);
167+
if (bean instanceof WebFilterChainProxy webFilterChainProxy) {
168+
return postProcess(webFilterChainProxy);
169169
}
170170
return bean;
171171
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/reactive/ReactiveCloudFoundrySecurityService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ Mono<AccessLevel> getAccessLevel(String token, String applicationId) throws Clou
9090
}
9191

9292
private Throwable mapError(Throwable throwable) {
93-
if (throwable instanceof WebClientResponseException) {
94-
HttpStatusCode statusCode = ((WebClientResponseException) throwable).getStatusCode();
93+
if (throwable instanceof WebClientResponseException webClientResponseException) {
94+
HttpStatusCode statusCode = webClientResponseException.getStatusCode();
9595
if (statusCode.equals(HttpStatus.FORBIDDEN)) {
9696
return new CloudFoundryAuthorizationException(Reason.ACCESS_DENIED, "Access denied");
9797
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/CloudFoundrySecurityInterceptor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ SecurityResponse preHandle(HttpServletRequest request, EndpointId endpointId) {
7777
}
7878
catch (Exception ex) {
7979
logger.error(ex);
80-
if (ex instanceof CloudFoundryAuthorizationException) {
81-
CloudFoundryAuthorizationException cfException = (CloudFoundryAuthorizationException) ex;
80+
if (ex instanceof CloudFoundryAuthorizationException cfException) {
8281
return new SecurityResponse(cfException.getStatusCode(),
8382
"{\"security_error\":\"" + cfException.getMessage() + "\"}");
8483
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/cloudfoundry/servlet/SkipSslVerificationHttpRequestFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-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.
@@ -40,8 +40,8 @@ class SkipSslVerificationHttpRequestFactory extends SimpleClientHttpRequestFacto
4040

4141
@Override
4242
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
43-
if (connection instanceof HttpsURLConnection) {
44-
prepareHttpsConnection((HttpsURLConnection) connection);
43+
if (connection instanceof HttpsURLConnection httpsURLConnection) {
44+
prepareHttpsConnection(httpsURLConnection);
4545
}
4646
super.prepareConnection(connection, httpMethod);
4747
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/condition/ConditionsReportEndpoint.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-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.
@@ -72,8 +72,8 @@ public ApplicationConditionEvaluation applicationConditionEvaluation() {
7272

7373
private ConfigurableApplicationContext getConfigurableParent(ConfigurableApplicationContext context) {
7474
ApplicationContext parent = context.getParent();
75-
if (parent instanceof ConfigurableApplicationContext) {
76-
return (ConfigurableApplicationContext) parent;
75+
if (parent instanceof ConfigurableApplicationContext configurableParent) {
76+
return configurableParent;
7777
}
7878
return null;
7979
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/AutoConfiguredHealthEndpointGroups.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -65,8 +65,8 @@ class AutoConfiguredHealthEndpointGroups implements HealthEndpointGroups {
6565
* @param properties the health endpoint properties
6666
*/
6767
AutoConfiguredHealthEndpointGroups(ApplicationContext applicationContext, HealthEndpointProperties properties) {
68-
ListableBeanFactory beanFactory = (applicationContext instanceof ConfigurableApplicationContext)
69-
? ((ConfigurableApplicationContext) applicationContext).getBeanFactory() : applicationContext;
68+
ListableBeanFactory beanFactory = (applicationContext instanceof ConfigurableApplicationContext configurableContext)
69+
? configurableContext.getBeanFactory() : applicationContext;
7070
Show showComponents = properties.getShowComponents();
7171
Show showDetails = properties.getShowDetails();
7272
Set<String> roles = properties.getRoles();

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ static class HealthEndpointGroupsBeanPostProcessor implements BeanPostProcessor
113113

114114
@Override
115115
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
116-
if (bean instanceof HealthEndpointGroups) {
117-
return applyPostProcessors((HealthEndpointGroups) bean);
116+
if (bean instanceof HealthEndpointGroups groups) {
117+
return applyPostProcessors(groups);
118118
}
119119
return bean;
120120
}
@@ -145,11 +145,11 @@ private static class AdaptedReactiveHealthContributors {
145145
}
146146

147147
private HealthContributor adapt(ReactiveHealthContributor contributor) {
148-
if (contributor instanceof ReactiveHealthIndicator) {
149-
return adapt((ReactiveHealthIndicator) contributor);
148+
if (contributor instanceof ReactiveHealthIndicator healthIndicator) {
149+
return adapt(healthIndicator);
150150
}
151-
if (contributor instanceof CompositeReactiveHealthContributor) {
152-
return adapt((CompositeReactiveHealthContributor) contributor);
151+
if (contributor instanceof CompositeReactiveHealthContributor healthContributor) {
152+
return adapt(healthContributor);
153153
}
154154
throw new IllegalStateException("Unsupported ReactiveHealthContributor type " + contributor.getClass());
155155
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/jdbc/DataSourceHealthContributorAutoConfiguration.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ private HealthContributor createContributor(Map<String, DataSource> beans) {
103103
}
104104

105105
private HealthContributor createContributor(DataSource source) {
106-
if (source instanceof AbstractRoutingDataSource) {
107-
AbstractRoutingDataSource routingDataSource = (AbstractRoutingDataSource) source;
106+
if (source instanceof AbstractRoutingDataSource routingDataSource) {
108107
return new RoutingDataSourceHealthContributor(routingDataSource, this::createContributor);
109108
}
110109
return new DataSourceHealthIndicator(source, getValidationQuery(source));

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/liquibase/LiquibaseEndpointAutoConfiguration.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public static BeanPostProcessor preventDataSourceCloseBeanPostProcessor() {
5757

5858
@Override
5959
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
60-
if (bean instanceof DataSourceClosingSpringLiquibase) {
61-
((DataSourceClosingSpringLiquibase) bean).setCloseDataSourceOnceMigrated(false);
60+
if (bean instanceof DataSourceClosingSpringLiquibase dataSource) {
61+
dataSource.setCloseDataSourceOnceMigrated(false);
6262
}
6363
return bean;
6464
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterRegistryPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-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,8 +60,8 @@ class MeterRegistryPostProcessor implements BeanPostProcessor {
6060

6161
@Override
6262
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
63-
if (bean instanceof MeterRegistry) {
64-
getConfigurer().configure((MeterRegistry) bean);
63+
if (bean instanceof MeterRegistry meterRegistry) {
64+
getConfigurer().configure(meterRegistry);
6565
}
6666
return bean;
6767
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2021 the original author or authors.
2+
* Copyright 2012-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.
@@ -63,18 +63,18 @@ public Double getValue(Type meterType) {
6363
}
6464

6565
private Double getDistributionSummaryValue() {
66-
if (this.value instanceof Double) {
67-
return (Double) this.value;
66+
if (this.value instanceof Double doubleValue) {
67+
return doubleValue;
6868
}
6969
return null;
7070
}
7171

7272
private Long getTimerValue() {
73-
if (this.value instanceof Double) {
74-
return TimeUnit.MILLISECONDS.toNanos(((Double) this.value).longValue());
73+
if (this.value instanceof Double doubleValue) {
74+
return TimeUnit.MILLISECONDS.toNanos(doubleValue.longValue());
7575
}
76-
if (this.value instanceof Duration) {
77-
return ((Duration) this.value).toNanos();
76+
if (this.value instanceof Duration duration) {
77+
return duration.toNanos();
7878
}
7979
return null;
8080
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/amqp/RabbitConnectionFactoryMetricsPostProcessor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-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.
@@ -49,8 +49,8 @@ class RabbitConnectionFactoryMetricsPostProcessor implements BeanPostProcessor,
4949

5050
@Override
5151
public Object postProcessAfterInitialization(Object bean, String beanName) {
52-
if (bean instanceof AbstractConnectionFactory) {
53-
bindConnectionFactoryToRegistry(getMeterRegistry(), beanName, (AbstractConnectionFactory) bean);
52+
if (bean instanceof AbstractConnectionFactory connectionFactory) {
53+
bindConnectionFactoryToRegistry(getMeterRegistry(), beanName, connectionFactory);
5454
}
5555
return bean;
5656
}

0 commit comments

Comments
 (0)