From 3d2a742328128945376bd13d947ff7f6db32346f Mon Sep 17 00:00:00 2001 From: Vedran Pavic Date: Mon, 23 Jul 2018 15:16:35 +0200 Subject: [PATCH] Use Spring Java Format Checkstyle Closes gh-1113 --- etc/checkstyle/checkstyle.xml | 158 +----------------- etc/checkstyle/suppressions.xml | 18 +- .../sample/session/SessionDetailsFilter.java | 4 +- .../UserRepositoryUserDetailsService.java | 4 +- .../websocket/WebSocketDisconnectHandler.java | 4 +- .../java/sample/ObjectStreamSerializer.java | 6 +- .../java/sample/RestTests.java | 2 +- .../src/main/java/sample/Initializer.java | 8 +- .../session/ReactiveMapSessionRepository.java | 2 +- .../org/springframework/session/Session.java | 6 +- .../http/SpringHttpSessionConfiguration.java | 10 +- .../session/events/AbstractSessionEvent.java | 4 +- ...SpringSessionBackedSessionInformation.java | 4 +- .../web/http/DefaultCookieSerializer.java | 10 +- .../web/http/HeaderHttpSessionIdResolver.java | 6 +- .../web/http/OnCommittedResponseWrapper.java | 6 +- .../session/SpringSessionWebSessionStore.java | 4 +- .../handler/WebSocketRegistryListener.java | 11 +- .../SessionRepositoryMessageInterceptor.java | 4 +- .../session/data/SessionEventRegistry.java | 4 +- ...isListenerContainerTaskExecutorITests.java | 4 +- ...ctiveRedisOperationsSessionRepository.java | 12 +- .../RedisOperationsSessionRepository.java | 7 +- .../ConfigureNotifyKeyspaceEventsAction.java | 6 +- .../redis/config/ConfigureRedisAction.java | 4 +- .../http/RedisHttpSessionConfiguration.java | 4 +- ...RedisOperationsSessionRepositoryTests.java | 8 +- .../RedisSessionExpirationPolicyTests.java | 6 +- .../hazelcast/SessionEventRegistry.java | 4 +- ...EnableHazelcastHttpSessionEventsTests.java | 2 +- ...JdbcOperationsSessionRepositoryITests.java | 16 +- .../jdbc/JdbcOperationsSessionRepository.java | 38 ++--- 32 files changed, 116 insertions(+), 270 deletions(-) diff --git a/etc/checkstyle/checkstyle.xml b/etc/checkstyle/checkstyle.xml index 23c7eb61..bba30aa9 100644 --- a/etc/checkstyle/checkstyle.xml +++ b/etc/checkstyle/checkstyle.xml @@ -2,165 +2,11 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/etc/checkstyle/suppressions.xml b/etc/checkstyle/suppressions.xml index 915c20fb..ff56025d 100644 --- a/etc/checkstyle/suppressions.xml +++ b/etc/checkstyle/suppressions.xml @@ -2,17 +2,15 @@ - - + + - - - - - + + + - - - + + + diff --git a/samples/boot/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java b/samples/boot/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java index f0056ad1..8ed4d01d 100644 --- a/samples/boot/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java +++ b/samples/boot/findbyusername/src/main/java/sample/session/SessionDetailsFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -92,7 +92,7 @@ public class SessionDetailsFilter extends OncePerRequestFilter { } return cityName + ", " + countryName; } - catch (Exception e) { + catch (Exception ex) { return UNKNOWN; } diff --git a/samples/boot/websocket/src/main/java/sample/security/UserRepositoryUserDetailsService.java b/samples/boot/websocket/src/main/java/sample/security/UserRepositoryUserDetailsService.java index fbb68a1d..43970eab 100644 --- a/samples/boot/websocket/src/main/java/sample/security/UserRepositoryUserDetailsService.java +++ b/samples/boot/websocket/src/main/java/sample/security/UserRepositoryUserDetailsService.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -59,7 +59,7 @@ public class UserRepositoryUserDetailsService implements UserDetailsService { return new CustomUserDetails(user); } - private final static class CustomUserDetails extends User implements UserDetails { + private static final class CustomUserDetails extends User implements UserDetails { private CustomUserDetails(User user) { super(user); diff --git a/samples/boot/websocket/src/main/java/sample/websocket/WebSocketDisconnectHandler.java b/samples/boot/websocket/src/main/java/sample/websocket/WebSocketDisconnectHandler.java index 4b31dd53..ad66dc47 100644 --- a/samples/boot/websocket/src/main/java/sample/websocket/WebSocketDisconnectHandler.java +++ b/samples/boot/websocket/src/main/java/sample/websocket/WebSocketDisconnectHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -42,7 +42,7 @@ public class WebSocketDisconnectHandler if (id == null) { return; } - this.repository.findById(id).ifPresent(user -> { + this.repository.findById(id).ifPresent((user) -> { this.repository.deleteById(id); this.messagingTemplate.convertAndSend("/topic/friends/signout", Arrays.asList(user.getUsername())); diff --git a/samples/javaconfig/hazelcast/src/main/java/sample/ObjectStreamSerializer.java b/samples/javaconfig/hazelcast/src/main/java/sample/ObjectStreamSerializer.java index 4d1eb444..633b0131 100644 --- a/samples/javaconfig/hazelcast/src/main/java/sample/ObjectStreamSerializer.java +++ b/samples/javaconfig/hazelcast/src/main/java/sample/ObjectStreamSerializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -55,8 +55,8 @@ public class ObjectStreamSerializer implements StreamSerializer { try { return in.readObject(); } - catch (ClassNotFoundException e) { - throw new IOException(e); + catch (ClassNotFoundException ex) { + throw new IOException(ex); } } diff --git a/samples/javaconfig/rest/src/integration-test/java/sample/RestTests.java b/samples/javaconfig/rest/src/integration-test/java/sample/RestTests.java index 2e6cab43..4239f9b7 100644 --- a/samples/javaconfig/rest/src/integration-test/java/sample/RestTests.java +++ b/samples/javaconfig/rest/src/integration-test/java/sample/RestTests.java @@ -59,7 +59,7 @@ public class RestTests { headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); assertThatThrownBy(() -> getForUser(this.baseUrl + "/", headers, String.class)) .isInstanceOf(HttpClientErrorException.class) - .satisfies(e -> assertThat(((HttpClientErrorException) e).getStatusCode()) + .satisfies((e) -> assertThat(((HttpClientErrorException) e).getStatusCode()) .isEqualTo(HttpStatus.UNAUTHORIZED)); } diff --git a/samples/misc/hazelcast/src/main/java/sample/Initializer.java b/samples/misc/hazelcast/src/main/java/sample/Initializer.java index a0ac28e2..4d21227a 100644 --- a/samples/misc/hazelcast/src/main/java/sample/Initializer.java +++ b/samples/misc/hazelcast/src/main/java/sample/Initializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -78,14 +78,14 @@ public class Initializer implements ServletContextListener { socket = new ServerSocket(0); return socket.getLocalPort(); } - catch (IOException e) { - throw new RuntimeException(e); + catch (IOException ex) { + throw new RuntimeException(ex); } finally { try { socket.close(); } - catch (IOException e) { + catch (IOException ex) { } } } diff --git a/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java b/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java index 36bdaf5f..d7287ae8 100644 --- a/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java +++ b/spring-session-core/src/main/java/org/springframework/session/ReactiveMapSessionRepository.java @@ -86,7 +86,7 @@ public class ReactiveMapSessionRepository implements ReactiveSessionRepository findById(String id) { // @formatter:off return Mono.defer(() -> Mono.justOrEmpty(this.sessions.get(id)) - .filter(session -> !session.isExpired()) + .filter((session) -> !session.isExpired()) .map(MapSession::new) .switchIfEmpty(deleteById(id).then(Mono.empty()))); // @formatter:on diff --git a/spring-session-core/src/main/java/org/springframework/session/Session.java b/spring-session-core/src/main/java/org/springframework/session/Session.java index 0dbdf911..383838ec 100644 --- a/spring-session-core/src/main/java/org/springframework/session/Session.java +++ b/spring-session-core/src/main/java/org/springframework/session/Session.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -47,7 +47,7 @@ public interface Session { * Gets the Object associated with the specified name or null if no Object is * associated to that name. * - * @param The return type of the attribute + * @param the return type of the attribute * @param attributeName the name of the attribute to get * @return the Object associated with the specified name or null if no Object is * associated to that name @@ -81,7 +81,7 @@ public interface Session { @SuppressWarnings("unchecked") default T getAttributeOrDefault(String name, T defaultValue) { T result = getAttribute(name); - return result == null ? defaultValue : result; + return (result != null ? result : defaultValue); } /** diff --git a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java index d381eafe..148ae974 100644 --- a/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java +++ b/spring-session-core/src/main/java/org/springframework/session/config/annotation/web/http/SpringHttpSessionConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -110,8 +110,8 @@ public class SpringHttpSessionConfiguration implements ApplicationContextAware { @PostConstruct public void init() { - CookieSerializer cookieSerializer = this.cookieSerializer != null - ? this.cookieSerializer : createDefaultCookieSerializer(); + CookieSerializer cookieSerializer = (this.cookieSerializer != null + ? this.cookieSerializer : createDefaultCookieSerializer()); this.defaultHttpSessionIdResolver.setCookieSerializer(cookieSerializer); } @@ -169,9 +169,9 @@ public class SpringHttpSessionConfiguration implements ApplicationContextAware { try { sessionCookieConfig = this.servletContext.getSessionCookieConfig(); } - catch (UnsupportedOperationException e) { + catch (UnsupportedOperationException ex) { this.logger - .warn("Unable to obtain SessionCookieConfig: " + e.getMessage()); + .warn("Unable to obtain SessionCookieConfig: " + ex.getMessage()); } if (sessionCookieConfig != null) { if (sessionCookieConfig.getName() != null) { diff --git a/spring-session-core/src/main/java/org/springframework/session/events/AbstractSessionEvent.java b/spring-session-core/src/main/java/org/springframework/session/events/AbstractSessionEvent.java index 6b99945d..9a31e6d1 100644 --- a/spring-session-core/src/main/java/org/springframework/session/events/AbstractSessionEvent.java +++ b/spring-session-core/src/main/java/org/springframework/session/events/AbstractSessionEvent.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -45,7 +45,7 @@ public abstract class AbstractSessionEvent extends ApplicationEvent { * implementations it may not be possible to get the original session in which case * this may be null. * - * @param The type of Session + * @param the type of Session * @return the expired {@link Session} or null if the data store does not support * obtaining it */ diff --git a/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java b/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java index d7baeb21..60b4268e 100644 --- a/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java +++ b/spring-session-core/src/main/java/org/springframework/session/security/SpringSessionBackedSessionInformation.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -63,7 +63,7 @@ class SpringSessionBackedSessionInformation /** * Tries to determine the principal's name from the given Session. * - * @param session Spring Session session + * @param session the session * @return the principal's name, or empty String if it couldn't be determined */ private static String resolvePrincipal(Session session) { diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java b/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java index e62ecc35..127be87f 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/DefaultCookieSerializer.java @@ -69,8 +69,8 @@ public class DefaultCookieSerializer implements CookieSerializer { if (cookies != null) { for (Cookie cookie : cookies) { if (this.cookieName.equals(cookie.getName())) { - String sessionId = this.useBase64Encoding - ? base64Decode(cookie.getValue()) : cookie.getValue(); + String sessionId = (this.useBase64Encoding + ? base64Decode(cookie.getValue()) : cookie.getValue()); if (sessionId == null) { continue; } @@ -97,8 +97,8 @@ public class DefaultCookieSerializer implements CookieSerializer { HttpServletResponse response = cookieValue.getResponse(); String requestedCookieValue = cookieValue.getCookieValue(); - String actualCookieValue = this.jvmRoute == null ? requestedCookieValue - : requestedCookieValue + this.jvmRoute; + String actualCookieValue = (this.jvmRoute != null + ? requestedCookieValue + this.jvmRoute : requestedCookieValue); Cookie sessionCookie = new Cookie(this.cookieName, this.useBase64Encoding ? base64Encode(actualCookieValue) : actualCookieValue); @@ -140,7 +140,7 @@ public class DefaultCookieSerializer implements CookieSerializer { byte[] decodedCookieBytes = Base64.getDecoder().decode(base64Value); return new String(decodedCookieBytes); } - catch (Exception e) { + catch (Exception ex) { return null; } } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/HeaderHttpSessionIdResolver.java b/spring-session-core/src/main/java/org/springframework/session/web/http/HeaderHttpSessionIdResolver.java index 9f8d8081..cf33d714 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/HeaderHttpSessionIdResolver.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/HeaderHttpSessionIdResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -98,8 +98,8 @@ public class HeaderHttpSessionIdResolver implements HttpSessionIdResolver { @Override public List resolveSessionIds(HttpServletRequest request) { String headerValue = request.getHeader(this.headerName); - return headerValue != null ? Collections.singletonList(headerValue) - : Collections.emptyList(); + return (headerValue != null ? Collections.singletonList(headerValue) + : Collections.emptyList()); } @Override diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java b/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java index c5e17479..a6dd6de7 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2018 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. @@ -174,11 +174,11 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper { } private void trackContentLength(byte[] content) { - checkContentLength(content == null ? 0 : content.length); + checkContentLength(content != null ? content.length : 0); } private void trackContentLength(char[] content) { - checkContentLength(content == null ? 0 : content.length); + checkContentLength(content != null ? content.length : 0); } private void trackContentLength(int content) { diff --git a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java index 327b45e6..25cacd47 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/server/session/SpringSessionWebSessionStore.java @@ -96,7 +96,7 @@ public class SpringSessionWebSessionStore implements WebSessi @Override public Mono retrieveSession(String sessionId) { return this.sessions.findById(sessionId) - .doOnNext(session -> session.setLastAccessedTime(this.clock.instant())) + .doOnNext((session) -> session.setLastAccessedTime(this.clock.instant())) .map(this::existingSession); } @@ -239,7 +239,7 @@ public class SpringSessionWebSessionStore implements WebSessi @Override public boolean containsValue(Object value) { return this.session.getAttributeNames().stream() - .anyMatch(attrName -> this.session.getAttribute(attrName) != null); + .anyMatch((attrName) -> this.session.getAttribute(attrName) != null); } @Override diff --git a/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java b/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java index 353006ee..68239522 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/socket/handler/WebSocketRegistryListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -71,8 +71,9 @@ public final class WebSocketRegistryListener SessionDisconnectEvent e = (SessionDisconnectEvent) event; Map sessionAttributes = SimpMessageHeaderAccessor .getSessionAttributes(e.getMessage().getHeaders()); - String httpSessionId = sessionAttributes == null ? null - : SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes); + String httpSessionId = (sessionAttributes != null + ? SessionRepositoryMessageInterceptor.getSessionId(sessionAttributes) + : null); afterConnectionClosed(httpSessionId, e.getSessionId()); } } @@ -140,10 +141,10 @@ public final class WebSocketRegistryListener try { toClose.close(SESSION_EXPIRED_STATUS); } - catch (IOException e) { + catch (IOException ex) { logger.debug( "Failed to close WebSocketSession (this is nothing to worry about but for debugging only)", - e); + ex); } } } diff --git a/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java b/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java index 3475bfac..02c296fe 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/socket/server/SessionRepositoryMessageInterceptor.java @@ -117,8 +117,8 @@ public final class SessionRepositoryMessageInterceptor } Map sessionHeaders = SimpMessageHeaderAccessor .getSessionAttributes(message.getHeaders()); - String sessionId = sessionHeaders == null ? null - : (String) sessionHeaders.get(SPRING_SESSION_ID_ATTR_NAME); + String sessionId = (sessionHeaders != null + ? (String) sessionHeaders.get(SPRING_SESSION_ID_ATTR_NAME) : null); if (sessionId != null) { S session = this.sessionRepository.findById(sessionId); if (session != null) { diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java index e7e97bc1..0d8b2dc3 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/SessionEventRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -66,6 +66,6 @@ public class SessionEventRegistry implements ApplicationListener new Object()); + return this.locks.computeIfAbsent(sessionId, (k) -> new Object()); } } diff --git a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java index fb221d2d..18e2fe26 100644 --- a/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java +++ b/spring-session-data-redis/src/integration-test/java/org/springframework/session/data/redis/taskexecutor/RedisListenerContainerTaskExecutorITests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -95,7 +95,7 @@ public class RedisListenerContainerTaskExecutorITests extends AbstractRedisITest synchronized (this.lock) { this.lock.wait(TimeUnit.SECONDS.toMillis(1)); } - return this.taskDispatched == null ? Boolean.FALSE : this.taskDispatched; + return (this.taskDispatched != null ? this.taskDispatched : Boolean.FALSE); } } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java index 9d769e23..26c8f513 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepository.java @@ -134,7 +134,7 @@ public class ReactiveRedisOperationsSessionRepository implements @Override public Mono save(RedisSession session) { - return session.saveDelta().and(s -> { + return session.saveDelta().and((s) -> { if (session.isNew) { session.setNew(false); } @@ -148,9 +148,9 @@ public class ReactiveRedisOperationsSessionRepository implements String sessionKey = getSessionKey(id); return this.sessionRedisOperations.opsForHash().entries(sessionKey) - .collectMap(e -> e.getKey().toString(), Map.Entry::getValue) - .filter(map -> !map.isEmpty()).map(new SessionMapper(id)) - .filter(session -> !session.isExpired()).map(RedisSession::new) + .collectMap((e) -> e.getKey().toString(), Map.Entry::getValue) + .filter((map) -> !map.isEmpty()).map(new SessionMapper(id)) + .filter((session) -> !session.isExpired()).map(RedisSession::new) .switchIfEmpty(Mono.defer(() -> deleteById(id).then(Mono.empty()))); } @@ -311,7 +311,7 @@ public class ReactiveRedisOperationsSessionRepository implements Mono setTtl = ReactiveRedisOperationsSessionRepository.this.sessionRedisOperations .expire(sessionKey, getMaxInactiveInterval()); - return changeSessionId.and(update).and(setTtl).and(s -> { + return changeSessionId.and(update).and(setTtl).and((s) -> { this.delta.clear(); s.onComplete(); }).then(); @@ -322,7 +322,7 @@ public class ReactiveRedisOperationsSessionRepository implements return Mono.empty(); } - Publisher replaceSessionId = s -> { + Publisher replaceSessionId = (s) -> { this.originalSessionId = sessionId; s.onComplete(); }; diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java index c947031a..ea8b625c 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/RedisOperationsSessionRepository.java @@ -316,7 +316,7 @@ public class RedisOperationsSessionRepository implements /** * Creates a new instance. For an example, refer to the class level javadoc. * - * @param sessionRedisOperations The {@link RedisOperations} to use for managing the + * @param sessionRedisOperations the {@link RedisOperations} to use for managing the * sessions. Cannot be null. */ public RedisOperationsSessionRepository( @@ -797,8 +797,9 @@ public class RedisOperationsSessionRepository implements this.delta = new HashMap<>(this.delta.size()); - Long originalExpiration = this.originalLastAccessTime == null ? null - : this.originalLastAccessTime.plus(getMaxInactiveInterval()).toEpochMilli(); + Long originalExpiration = (this.originalLastAccessTime != null + ? this.originalLastAccessTime.plus(getMaxInactiveInterval()).toEpochMilli() + : null); RedisOperationsSessionRepository.this.expirationPolicy .onExpirationUpdated(originalExpiration, this); } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java index 4fafaa71..4355e132 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureNotifyKeyspaceEventsAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -79,10 +79,10 @@ public class ConfigureNotifyKeyspaceEventsAction implements ConfigureRedisAction } return config.getProperty(config.stringPropertyNames().iterator().next()); } - catch (InvalidDataAccessApiUsageException e) { + catch (InvalidDataAccessApiUsageException ex) { throw new IllegalStateException( "Unable to configure Redis to keyspace notifications. See http://docs.spring.io/spring-session/docs/current/reference/html5/#api-redisoperationssessionrepository-sessiondestroyedevent", - e); + ex); } } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java index d448192f..90744403 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/ConfigureRedisAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -31,7 +31,7 @@ public interface ConfigureRedisAction { /** * A do nothing implementation of {@link ConfigureRedisAction}. */ - ConfigureRedisAction NO_OP = connection -> { + ConfigureRedisAction NO_OP = (connection) -> { }; } diff --git a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java index a030414b..50888ff4 100644 --- a/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java +++ b/spring-session-data-redis/src/main/java/org/springframework/session/data/redis/config/annotation/web/http/RedisHttpSessionConfiguration.java @@ -289,9 +289,9 @@ public class RedisHttpSessionConfiguration extends SpringHttpSessionConfiguratio try { connection.close(); } - catch (Exception e) { + catch (Exception ex) { LogFactory.getLog(getClass()).error("Error closing RedisConnection", - e); + ex); } } } diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java index 4480182b..a4b52a1b 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/ReactiveRedisOperationsSessionRepositoryTests.java @@ -133,7 +133,7 @@ public class ReactiveRedisOperationsSessionRepositoryTests { @Test public void createSessionDefaultMaxInactiveInterval() { StepVerifier.create(this.repository.createSession()).consumeNextWith( - session -> assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration + (session) -> assertThat(session.getMaxInactiveInterval()).isEqualTo(Duration .ofSeconds(MapSession.DEFAULT_MAX_INACTIVE_INTERVAL_SECONDS))) .verifyComplete(); } @@ -143,7 +143,7 @@ public class ReactiveRedisOperationsSessionRepositoryTests { this.repository.setDefaultMaxInactiveInterval(600); StepVerifier.create(this.repository.createSession()) - .consumeNextWith(session -> assertThat(session.getMaxInactiveInterval()) + .consumeNextWith((session) -> assertThat(session.getMaxInactiveInterval()) .isEqualTo(Duration.ofSeconds(600))) .verifyComplete(); } @@ -157,7 +157,7 @@ public class ReactiveRedisOperationsSessionRepositoryTests { StepVerifier .create(this.repository.createSession().doOnNext(this.repository::save)) - .consumeNextWith(session -> { + .consumeNextWith((session) -> { verify(this.redisOperations).opsForHash(); verify(this.hashOperations).putAll(anyString(), this.delta.capture()); verify(this.redisOperations).expire(anyString(), any()); @@ -325,7 +325,7 @@ public class ReactiveRedisOperationsSessionRepositoryTests { given(this.hashOperations.entries(anyString())) .willReturn(Flux.fromIterable(map.entrySet())); - StepVerifier.create(this.repository.findById("test")).consumeNextWith(session -> { + StepVerifier.create(this.repository.findById("test")).consumeNextWith((session) -> { verify(this.redisOperations).opsForHash(); verify(this.hashOperations).entries(anyString()); verifyZeroInteractions(this.redisOperations); diff --git a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java index 7ee07b2e..fe5332f3 100644 --- a/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java +++ b/spring-session-data-redis/src/test/java/org/springframework/session/data/redis/RedisSessionExpirationPolicyTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -43,10 +43,10 @@ import static org.mockito.Mockito.verify; @RunWith(MockitoJUnitRunner.class) public class RedisSessionExpirationPolicyTests { // Wed Apr 15 10:28:32 CDT 2015 - final static Long NOW = 1429111712346L; + static final Long NOW = 1429111712346L; // Wed Apr 15 10:27:32 CDT 2015 - final static Long ONE_MINUTE_AGO = 1429111652346L; + static final Long ONE_MINUTE_AGO = 1429111652346L; @Mock RedisOperations sessionRedisOperations; diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventRegistry.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventRegistry.java index ee861cfd..7a9f01cd 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventRegistry.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/SessionEventRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2018 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. @@ -66,6 +66,6 @@ public class SessionEventRegistry implements ApplicationListener new Object()); + return this.locks.computeIfAbsent(sessionId, (k) -> new Object()); } } diff --git a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java index 5070da0d..76f953db 100644 --- a/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java +++ b/spring-session-hazelcast/src/integration-test/java/org/springframework/session/hazelcast/config/annotation/web/http/EnableHazelcastHttpSessionEventsTests.java @@ -59,7 +59,7 @@ import static org.assertj.core.api.Assertions.assertThat; @WebAppConfiguration public class EnableHazelcastHttpSessionEventsTests { - private final static int MAX_INACTIVE_INTERVAL_IN_SECONDS = 1; + private static final int MAX_INACTIVE_INTERVAL_IN_SECONDS = 1; @Autowired private SessionRepository repository; diff --git a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java index 272b8580..1a9ea141 100644 --- a/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java +++ b/spring-session-jdbc/src/integration-test/java/org/springframework/session/jdbc/AbstractJdbcOperationsSessionRepositoryITests.java @@ -237,7 +237,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -263,7 +263,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -309,7 +309,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -360,7 +360,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -423,7 +423,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -448,7 +448,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -491,7 +491,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); @@ -539,7 +539,7 @@ public abstract class AbstractJdbcOperationsSessionRepositoryITests { assertThat(findByPrincipalName).hasSize(1); assertThat(findByPrincipalName.keySet()).containsOnly(toSave.getId()); - findByPrincipalName.values().forEach(session -> { + findByPrincipalName.values().forEach((session) -> { assertThat(session.isChanged()).isFalse(); assertThat(session.getDelta()).isEmpty(); }); diff --git a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java index 619ae4f2..f34fab84 100644 --- a/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java +++ b/spring-session-jdbc/src/main/java/org/springframework/session/jdbc/JdbcOperationsSessionRepository.java @@ -372,7 +372,7 @@ public class JdbcOperationsSessionRepository implements protected void doInTransactionWithoutResult(TransactionStatus status) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.createSessionQuery, - ps -> { + (ps) -> { ps.setString(1, session.primaryKey); ps.setString(2, session.getId()); ps.setLong(3, session.getCreationTime().toEpochMilli()); @@ -397,7 +397,7 @@ public class JdbcOperationsSessionRepository implements if (session.isChanged()) { JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.updateSessionQuery, - ps -> { + (ps) -> { ps.setString(1, session.getId()); ps.setLong(2, session.getLastAccessedTime().toEpochMilli()); ps.setInt(3, (int) session.getMaxInactiveInterval().getSeconds()); @@ -407,17 +407,17 @@ public class JdbcOperationsSessionRepository implements }); } List addedAttributeNames = session.delta.entrySet().stream() - .filter(entry -> entry.getValue() == DeltaValue.ADDED) + .filter((entry) -> entry.getValue() == DeltaValue.ADDED) .map(Map.Entry::getKey) .collect(Collectors.toList()); insertSessionAttributes(session, addedAttributeNames); List updatedAttributeNames = session.delta.entrySet().stream() - .filter(entry -> entry.getValue() == DeltaValue.UPDATED) + .filter((entry) -> entry.getValue() == DeltaValue.UPDATED) .map(Map.Entry::getKey) .collect(Collectors.toList()); updateSessionAttributes(session, updatedAttributeNames); List removedAttributeNames = session.delta.entrySet().stream() - .filter(entry -> entry.getValue() == DeltaValue.REMOVED) + .filter((entry) -> entry.getValue() == DeltaValue.REMOVED) .map(Map.Entry::getKey) .collect(Collectors.toList()); deleteSessionAttributes(session, removedAttributeNames); @@ -430,10 +430,10 @@ public class JdbcOperationsSessionRepository implements @Override public JdbcSession findById(final String id) { - final JdbcSession session = this.transactionOperations.execute(status -> { + final JdbcSession session = this.transactionOperations.execute((status) -> { List sessions = JdbcOperationsSessionRepository.this.jdbcOperations.query( JdbcOperationsSessionRepository.this.getSessionQuery, - ps -> ps.setString(1, id), + (ps) -> ps.setString(1, id), JdbcOperationsSessionRepository.this.extractor ); if (sessions.isEmpty()) { @@ -473,10 +473,10 @@ public class JdbcOperationsSessionRepository implements return Collections.emptyMap(); } - List sessions = this.transactionOperations.execute(status -> + List sessions = this.transactionOperations.execute((status) -> JdbcOperationsSessionRepository.this.jdbcOperations.query( JdbcOperationsSessionRepository.this.listSessionsByPrincipalNameQuery, - ps -> ps.setString(1, indexValue), + (ps) -> ps.setString(1, indexValue), JdbcOperationsSessionRepository.this.extractor)); Map sessionMap = new HashMap<>( @@ -512,7 +512,7 @@ public class JdbcOperationsSessionRepository implements }); } else { - this.jdbcOperations.update(this.createSessionAttributeQuery, ps -> { + this.jdbcOperations.update(this.createSessionAttributeQuery, (ps) -> { String attributeName = attributeNames.get(0); ps.setString(1, session.primaryKey); ps.setString(2, attributeName); @@ -544,7 +544,7 @@ public class JdbcOperationsSessionRepository implements }); } else { - this.jdbcOperations.update(this.updateSessionAttributeQuery, ps -> { + this.jdbcOperations.update(this.updateSessionAttributeQuery, (ps) -> { String attributeName = attributeNames.get(0); serialize(ps, 1, session.getAttribute(attributeName)); ps.setString(2, session.primaryKey); @@ -575,7 +575,7 @@ public class JdbcOperationsSessionRepository implements }); } else { - this.jdbcOperations.update(this.deleteSessionAttributeQuery, ps -> { + this.jdbcOperations.update(this.deleteSessionAttributeQuery, (ps) -> { String attributeName = attributeNames.get(0); ps.setString(1, session.primaryKey); ps.setString(2, attributeName); @@ -584,7 +584,7 @@ public class JdbcOperationsSessionRepository implements } public void cleanUpExpiredSessions() { - Integer deletedCount = this.transactionOperations.execute(transactionStatus -> + Integer deletedCount = this.transactionOperations.execute((status) -> JdbcOperationsSessionRepository.this.jdbcOperations.update( JdbcOperationsSessionRepository.this.deleteSessionsByExpiryTimeQuery, System.currentTimeMillis())); @@ -740,22 +740,22 @@ public class JdbcOperationsSessionRepository implements if (attributeExists) { if (attributeRemoved) { this.delta.merge(attributeName, DeltaValue.REMOVED, - (oldDeltaValue, deltaValue) -> oldDeltaValue == DeltaValue.ADDED + (oldDeltaValue, deltaValue) -> (oldDeltaValue == DeltaValue.ADDED ? null - : deltaValue); + : deltaValue)); } else { this.delta.merge(attributeName, DeltaValue.UPDATED, - (oldDeltaValue, deltaValue) -> oldDeltaValue == DeltaValue.ADDED + (oldDeltaValue, deltaValue) -> (oldDeltaValue == DeltaValue.ADDED ? oldDeltaValue - : deltaValue); + : deltaValue)); } } else { this.delta.merge(attributeName, DeltaValue.ADDED, - (oldDeltaValue, deltaValue) -> oldDeltaValue == DeltaValue.ADDED + (oldDeltaValue, deltaValue) -> (oldDeltaValue == DeltaValue.ADDED ? oldDeltaValue - : DeltaValue.UPDATED); + : DeltaValue.UPDATED)); } this.delegate.setAttribute(attributeName, attributeValue); if (PRINCIPAL_NAME_INDEX_NAME.equals(attributeName) ||