diff --git a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java index 7589a95e953..7130bdb5112 100644 --- a/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java +++ b/spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassEnhancer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -189,7 +189,7 @@ class ConfigurationClassEnhancer { public int accept(Method method) { for (int i = 0; i < this.callbacks.length; i++) { Callback callback = this.callbacks[i]; - if (!(callback instanceof ConditionalCallback) || ((ConditionalCallback) callback).isMatch(method)) { + if (!(callback instanceof ConditionalCallback conditional) || conditional.isMatch(method)) { return i; } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java index 6f14c748e0d..6df9612ecad 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/DataSourceUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-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. @@ -402,7 +402,7 @@ public abstract class DataSourceUtils { * @see SmartDataSource#shouldClose(Connection) */ public static void doCloseConnection(Connection con, @Nullable DataSource dataSource) throws SQLException { - if (!(dataSource instanceof SmartDataSource) || ((SmartDataSource) dataSource).shouldClose(con)) { + if (!(dataSource instanceof SmartDataSource smartDataSource) || smartDataSource.shouldClose(con)) { con.close(); } } diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java index da2e86a879b..9360139abb1 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlEncodingFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-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. @@ -54,14 +54,14 @@ public class ResourceUrlEncodingFilter extends GenericFilterBean { public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws ServletException, IOException { - if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) { + if (!(request instanceof HttpServletRequest httpRequest) || !(response instanceof HttpServletResponse httpResponse)) { throw new ServletException("ResourceUrlEncodingFilter only supports HTTP requests"); } ResourceUrlEncodingRequestWrapper wrappedRequest = - new ResourceUrlEncodingRequestWrapper((HttpServletRequest) request); + new ResourceUrlEncodingRequestWrapper(httpRequest); ResourceUrlEncodingResponseWrapper wrappedResponse = - new ResourceUrlEncodingResponseWrapper(wrappedRequest, (HttpServletResponse) response); + new ResourceUrlEncodingResponseWrapper(wrappedRequest, httpResponse); filterChain.doFilter(wrappedRequest, wrappedResponse); }