mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-06 17:29:19 +00:00
Use instanceof pattern matching to avoid an explicit cast
See gh-51896 Signed-off-by: Tran Ngoc Nhan <ngocnhan.tran1996@gmail.com>
This commit is contained in:
committed by
Phillip Webb
parent
e4b2ecf934
commit
68c321499a
+2
-2
@@ -56,8 +56,8 @@ public class DispatcherFilter implements Filter {
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
|
||||
doFilter((HttpServletRequest) request, (HttpServletResponse) response, chain);
|
||||
if (request instanceof HttpServletRequest req && response instanceof HttpServletResponse res) {
|
||||
doFilter(req, res, chain);
|
||||
}
|
||||
else {
|
||||
chain.doFilter(request, response);
|
||||
|
||||
+5
-5
@@ -357,11 +357,11 @@ public class Restarter {
|
||||
Field field = type.getDeclaredField(fieldName);
|
||||
field.setAccessible(true);
|
||||
Object instance = field.get(null);
|
||||
if (instance instanceof Set) {
|
||||
((Set<?>) instance).clear();
|
||||
if (instance instanceof Set<?> set) {
|
||||
set.clear();
|
||||
}
|
||||
if (instance instanceof Map) {
|
||||
((Map<?, ?>) instance).keySet().removeIf(this::isFromRestartClassLoader);
|
||||
if (instance instanceof Map<?, ?> map) {
|
||||
map.keySet().removeIf(this::isFromRestartClassLoader);
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
@@ -372,7 +372,7 @@ public class Restarter {
|
||||
}
|
||||
|
||||
private boolean isFromRestartClassLoader(Object object) {
|
||||
return (object instanceof Class && ((Class<?>) object).getClassLoader() instanceof RestartClassLoader);
|
||||
return (object instanceof Class<?> cls && cls.getClassLoader() instanceof RestartClassLoader);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user