Skip to content

Commit 874077d

Browse files
committed
Apply "advanced" instanceof pattern matching
1 parent 578d3f4 commit 874077d

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.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.
@@ -189,7 +189,7 @@ public ConditionalCallbackFilter(Callback[] callbacks) {
189189
public int accept(Method method) {
190190
for (int i = 0; i < this.callbacks.length; i++) {
191191
Callback callback = this.callbacks[i];
192-
if (!(callback instanceof ConditionalCallback) || ((ConditionalCallback) callback).isMatch(method)) {
192+
if (!(callback instanceof ConditionalCallback conditional) || conditional.isMatch(method)) {
193193
return i;
194194
}
195195
}

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.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.
@@ -402,7 +402,7 @@ public static void doReleaseConnection(@Nullable Connection con, @Nullable DataS
402402
* @see SmartDataSource#shouldClose(Connection)
403403
*/
404404
public static void doCloseConnection(Connection con, @Nullable DataSource dataSource) throws SQLException {
405-
if (!(dataSource instanceof SmartDataSource) || ((SmartDataSource) dataSource).shouldClose(con)) {
405+
if (!(dataSource instanceof SmartDataSource smartDataSource) || smartDataSource.shouldClose(con)) {
406406
con.close();
407407
}
408408
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java

Lines changed: 4 additions & 4 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.
@@ -54,14 +54,14 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean {
5454
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
5555
throws ServletException, IOException {
5656

57-
if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
57+
if (!(request instanceof HttpServletRequest httpRequest) || !(response instanceof HttpServletResponse httpResponse)) {
5858
throw new ServletException("ResourceUrlEncodingFilter only supports HTTP requests");
5959
}
6060

6161
ResourceUrlEncodingRequestWrapper wrappedRequest =
62-
new ResourceUrlEncodingRequestWrapper((HttpServletRequest) request);
62+
new ResourceUrlEncodingRequestWrapper(httpRequest);
6363
ResourceUrlEncodingResponseWrapper wrappedResponse =
64-
new ResourceUrlEncodingResponseWrapper(wrappedRequest, (HttpServletResponse) response);
64+
new ResourceUrlEncodingResponseWrapper(wrappedRequest, httpResponse);
6565

6666
filterChain.doFilter(wrappedRequest, wrappedResponse);
6767
}

0 commit comments

Comments
 (0)