From 6c4baa00a6605340bf68ef1a2d0cf2e4b1271de6 Mon Sep 17 00:00:00 2001 From: Greg Turnquist Date: Tue, 12 Mar 2019 11:22:39 -0500 Subject: [PATCH] Add Nullable checks. Resolves #55. --- pom.xml | 7 ++++ .../mongo/AbstractMongoSessionConverter.java | 3 ++ .../session/data/mongo/Assert.java | 36 +++++++++++++++++++ .../data/mongo/AuthenticationParser.java | 4 ++- .../mongo/JacksonMongoSessionConverter.java | 3 ++ .../data/mongo/JdkMongoSessionConverter.java | 11 ++++-- .../MongoOperationsSessionRepository.java | 15 ++++++-- .../session/data/mongo/MongoSession.java | 2 ++ .../session/data/mongo/MongoSessionUtils.java | 3 ++ ...ctiveMongoOperationsSessionRepository.java | 10 ++++-- .../http/MongoHttpSessionConfiguration.java | 8 +++-- .../annotation/web/http/package-info.java | 23 ++++++++++++ .../config/annotation/web/package-info.java | 23 ++++++++++++ .../ReactiveMongoWebSessionConfiguration.java | 8 +++-- .../annotation/web/reactive/package-info.java | 23 ++++++++++++ .../session/data/mongo/package-info.java | 23 ++++++++++++ .../AbstractMongoSessionConverterTest.java | 3 ++ .../integration/AbstractClassLoaderTest.java | 5 +-- .../AbstractMongoRepositoryITest.java | 2 +- .../integration/SessionEventRegistry.java | 11 ++---- 20 files changed, 199 insertions(+), 24 deletions(-) create mode 100644 src/main/java/org/springframework/session/data/mongo/Assert.java create mode 100644 src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/package-info.java create mode 100644 src/main/java/org/springframework/session/data/mongo/config/annotation/web/package-info.java create mode 100644 src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/package-info.java create mode 100644 src/main/java/org/springframework/session/data/mongo/package-info.java diff --git a/pom.xml b/pom.xml index 375f1e6..e54e50b 100644 --- a/pom.xml +++ b/pom.xml @@ -73,6 +73,7 @@ 1.50.5 1.3 2.9.1 + 3.0.2 4.12 1.18.0 2.18.3 @@ -529,6 +530,12 @@ + + + com.google.code.findbugs + jsr305 + ${jsr305.version} + org.assertj diff --git a/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java b/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java index 5ebf40e..3d4bca9 100644 --- a/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java +++ b/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java @@ -29,6 +29,7 @@ import org.springframework.data.mongodb.core.index.Index; import org.springframework.data.mongodb.core.index.IndexInfo; import org.springframework.data.mongodb.core.index.IndexOperations; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.lang.Nullable; import org.springframework.session.FindByIndexNameSessionRepository; import org.springframework.session.Session; @@ -55,6 +56,7 @@ public abstract class AbstractMongoSessionConverter implements GenericConverter * @param indexValue value to query against * @return built query or null if indexName is not supported */ + @Nullable protected abstract Query getQueryForIndex(String indexName, Object indexValue); /** @@ -95,6 +97,7 @@ public abstract class AbstractMongoSessionConverter implements GenericConverter } @SuppressWarnings("unchecked") + @Nullable public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor targetType) { if (source == null) { diff --git a/src/main/java/org/springframework/session/data/mongo/Assert.java b/src/main/java/org/springframework/session/data/mongo/Assert.java new file mode 100644 index 0000000..0dbfcdb --- /dev/null +++ b/src/main/java/org/springframework/session/data/mongo/Assert.java @@ -0,0 +1,36 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.session.data.mongo; + +import org.springframework.lang.Nullable; + +/** + * @author Greg Turnquist + */ +public final class Assert { + + private Assert() {} + + public static T requireNonNull(@Nullable T item, String message) { + + if (item == null) { + throw new IllegalArgumentException(message); + } + + return item; + } + +} diff --git a/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java b/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java index 0ef73de..3895e29 100644 --- a/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java +++ b/src/main/java/org/springframework/session/data/mongo/AuthenticationParser.java @@ -17,6 +17,7 @@ package org.springframework.session.data.mongo; import org.springframework.expression.Expression; import org.springframework.expression.spel.standard.SpelExpressionParser; +import org.springframework.lang.Nullable; /** * Utility class to extract principal name from {@code Authentication} object. @@ -38,7 +39,8 @@ final class AuthenticationParser { * @param authentication Authentication object * @return principal name */ - static String extractName(Object authentication) { + @Nullable + static String extractName(@Nullable Object authentication) { if (authentication == null) { return null; diff --git a/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java b/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java index 9a9d209..477ed84 100644 --- a/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java +++ b/src/main/java/org/springframework/session/data/mongo/JacksonMongoSessionConverter.java @@ -26,6 +26,7 @@ import org.bson.json.JsonMode; import org.bson.json.JsonWriterSettings; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.lang.Nullable; import org.springframework.security.jackson2.SecurityJackson2Modules; import org.springframework.session.FindByIndexNameSessionRepository; import org.springframework.util.Assert; @@ -72,6 +73,7 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter this.objectMapper = objectMapper; } + @Nullable protected Query getQueryForIndex(String indexName, Object indexValue) { if (FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) { @@ -114,6 +116,7 @@ public class JacksonMongoSessionConverter extends AbstractMongoSessionConverter } @Override + @Nullable protected MongoSession convert(Document source) { String json = source.toJson(JsonWriterSettings.builder().outputMode(JsonMode.RELAXED).build()); diff --git a/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java b/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java index 96be252..bbbd09b 100644 --- a/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java +++ b/src/main/java/org/springframework/session/data/mongo/JdkMongoSessionConverter.java @@ -29,6 +29,7 @@ import org.springframework.core.serializer.support.DeserializingConverter; import org.springframework.core.serializer.support.SerializingConverter; import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Query; +import org.springframework.lang.Nullable; import org.springframework.session.FindByIndexNameSessionRepository; import org.springframework.session.Session; import org.springframework.util.Assert; @@ -64,7 +65,7 @@ public class JdkMongoSessionConverter extends AbstractMongoSessionConverter { public JdkMongoSessionConverter(Converter serializer, Converter deserializer, Duration maxInactiveInterval) { - + Assert.notNull(serializer, "serializer cannot be null"); Assert.notNull(deserializer, "deserializer cannot be null"); Assert.notNull(maxInactiveInterval, "maxInactiveInterval cannot be null"); @@ -74,6 +75,7 @@ public class JdkMongoSessionConverter extends AbstractMongoSessionConverter { } @Override + @Nullable public Query getQueryForIndex(String indexName, Object indexValue) { if (FindByIndexNameSessionRepository.PRINCIPAL_NAME_INDEX_NAME.equals(indexName)) { @@ -130,6 +132,7 @@ public class JdkMongoSessionConverter extends AbstractMongoSessionConverter { return session; } + @Nullable private byte[] serializeAttributes(Session session) { Map attributes = new HashMap<>(); @@ -151,8 +154,10 @@ public class JdkMongoSessionConverter extends AbstractMongoSessionConverter { Map attributes = (Map) this.deserializer.convert(attributesBytes); - for (Map.Entry entry : attributes.entrySet()) { - session.setAttribute(entry.getKey(), entry.getValue()); + if (attributes != null) { + for (Map.Entry entry : attributes.entrySet()) { + session.setAttribute(entry.getKey(), entry.getValue()); + } } } } diff --git a/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java b/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java index f082cea..5058cbd 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoOperationsSessionRepository.java @@ -35,6 +35,7 @@ import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.index.IndexOperations; +import org.springframework.lang.Nullable; import org.springframework.session.FindByIndexNameSessionRepository; import org.springframework.session.events.SessionCreatedEvent; import org.springframework.session.events.SessionDeletedEvent; @@ -89,10 +90,12 @@ public class MongoOperationsSessionRepository @Override public void save(MongoSession session) { - this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName); + this.mongoOperations.save(Assert.requireNonNull(convertToDBObject(this.mongoSessionConverter, session), + "convertToDBObject must not null!"), this.collectionName); } @Override + @Nullable public MongoSession findById(String id) { Document sessionWrapper = findSession(id); @@ -103,7 +106,7 @@ public class MongoOperationsSessionRepository MongoSession session = convertToSession(this.mongoSessionConverter, sessionWrapper); - if (session.isExpired()) { + if (session != null && session.isExpired()) { publishEvent(new SessionExpiredEvent(this, session)); deleteById(id); @@ -135,7 +138,12 @@ public class MongoOperationsSessionRepository public void deleteById(String id) { Optional.ofNullable(findSession(id)).ifPresent(document -> { - publishEvent(new SessionDeletedEvent(this, convertToSession(this.mongoSessionConverter, document))); + + MongoSession session = convertToSession(this.mongoSessionConverter, document); + if (session != null) { + publishEvent(new SessionDeletedEvent(this, session)); + } + this.mongoOperations.remove(document, this.collectionName); }); } @@ -147,6 +155,7 @@ public class MongoOperationsSessionRepository this.mongoSessionConverter.ensureIndexes(indexOperations); } + @Nullable private Document findSession(String id) { return this.mongoOperations.findById(id, Document.class, this.collectionName); } diff --git a/src/main/java/org/springframework/session/data/mongo/MongoSession.java b/src/main/java/org/springframework/session/data/mongo/MongoSession.java index 6d18530..d1286ea 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoSession.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoSession.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; +import org.springframework.lang.Nullable; import org.springframework.session.Session; /** @@ -83,6 +84,7 @@ public class MongoSession implements Session { } @Override + @Nullable public T getAttribute(String attributeName) { return (T) this.attrs.get(coverDot(attributeName)); } diff --git a/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java b/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java index 11a294a..9a4ce90 100644 --- a/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java +++ b/src/main/java/org/springframework/session/data/mongo/MongoSessionUtils.java @@ -17,6 +17,7 @@ package org.springframework.session.data.mongo; import org.bson.Document; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; import com.mongodb.DBObject; @@ -25,12 +26,14 @@ import com.mongodb.DBObject; */ public final class MongoSessionUtils { + @Nullable static DBObject convertToDBObject(AbstractMongoSessionConverter mongoSessionConverter, MongoSession session) { return (DBObject) mongoSessionConverter.convert(session, TypeDescriptor.valueOf(MongoSession.class), TypeDescriptor.valueOf(DBObject.class)); } + @Nullable static MongoSession convertToSession(AbstractMongoSessionConverter mongoSessionConverter, Document session) { return (MongoSession) mongoSessionConverter.convert(session, TypeDescriptor.valueOf(Document.class), diff --git a/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java b/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java index 54473b1..0e0ae73 100644 --- a/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java +++ b/src/main/java/org/springframework/session/data/mongo/ReactiveMongoOperationsSessionRepository.java @@ -37,6 +37,8 @@ import org.springframework.session.ReactiveSessionRepository; import org.springframework.session.events.SessionCreatedEvent; import org.springframework.session.events.SessionDeletedEvent; +import com.mongodb.DBObject; + /** * @author Greg Turnquist */ @@ -100,8 +102,12 @@ public class ReactiveMongoOperationsSessionRepository @Override public Mono save(MongoSession session) { - return this.mongoOperations.save(convertToDBObject(this.mongoSessionConverter, session), this.collectionName) - .then(); + DBObject dbObject = convertToDBObject(this.mongoSessionConverter, session); + if (dbObject != null) { + return this.mongoOperations.save(dbObject, this.collectionName).then(); + } else { + return Mono.empty(); + } } /** diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java index bc96453..bf5288b 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/MongoHttpSessionConfiguration.java @@ -88,9 +88,13 @@ public class MongoHttpSessionConfiguration extends SpringHttpSessionConfiguratio AnnotationAttributes attributes = AnnotationAttributes .fromMap(importMetadata.getAnnotationAttributes(EnableMongoHttpSession.class.getName())); - this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); + if (attributes != null) { + this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); + } else { + this.maxInactiveIntervalInSeconds = MongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL; + } - String collectionNameValue = attributes.getString("collectionName"); + String collectionNameValue = attributes != null ? attributes.getString("collectionName") : ""; if (StringUtils.hasText(collectionNameValue)) { this.collectionName = this.embeddedValueResolver.resolveStringValue(collectionNameValue); } diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/package-info.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/package-info.java new file mode 100644 index 0000000..9bc11aa --- /dev/null +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/http/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Greg Turnquist + */ +@NonNullApi +package org.springframework.session.data.mongo.config.annotation.web.http; + +import org.springframework.lang.NonNullApi; diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/package-info.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/package-info.java new file mode 100644 index 0000000..80068b6 --- /dev/null +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Greg Turnquist + */ +@NonNullApi +package org.springframework.session.data.mongo.config.annotation.web; + +import org.springframework.lang.NonNullApi; diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java index b0b4502..88c74f2 100644 --- a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/ReactiveMongoWebSessionConfiguration.java @@ -95,9 +95,13 @@ public class ReactiveMongoWebSessionConfiguration extends SpringWebSessionConfig AnnotationAttributes attributes = AnnotationAttributes .fromMap(importMetadata.getAnnotationAttributes(EnableMongoWebSession.class.getName())); - this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); + if (attributes != null) { + this.maxInactiveIntervalInSeconds = attributes.getNumber("maxInactiveIntervalInSeconds"); + } else { + this.maxInactiveIntervalInSeconds = ReactiveMongoOperationsSessionRepository.DEFAULT_INACTIVE_INTERVAL; + } - String collectionNameValue = attributes.getString("collectionName"); + String collectionNameValue = attributes != null ? attributes.getString("collectionName") : ""; if (StringUtils.hasText(collectionNameValue)) { this.collectionName = this.embeddedValueResolver.resolveStringValue(collectionNameValue); } diff --git a/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/package-info.java b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/package-info.java new file mode 100644 index 0000000..76eb77d --- /dev/null +++ b/src/main/java/org/springframework/session/data/mongo/config/annotation/web/reactive/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Greg Turnquist + */ +@NonNullApi +package org.springframework.session.data.mongo.config.annotation.web.reactive; + +import org.springframework.lang.NonNullApi; diff --git a/src/main/java/org/springframework/session/data/mongo/package-info.java b/src/main/java/org/springframework/session/data/mongo/package-info.java new file mode 100644 index 0000000..1e0c829 --- /dev/null +++ b/src/main/java/org/springframework/session/data/mongo/package-info.java @@ -0,0 +1,23 @@ +/* + * Copyright 2019 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @author Greg Turnquist + */ +@NonNullApi +package org.springframework.session.data.mongo; + +import org.springframework.lang.NonNullApi; diff --git a/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java b/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java index bed5346..3381f1d 100644 --- a/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java +++ b/src/test/java/org/springframework/session/data/mongo/AbstractMongoSessionConverterTest.java @@ -22,6 +22,7 @@ import java.time.Duration; import org.bson.Document; import org.junit.Test; import org.springframework.core.convert.TypeDescriptor; +import org.springframework.lang.Nullable; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.context.SecurityContextImpl; import org.springframework.session.FindByIndexNameSessionRepository; @@ -125,11 +126,13 @@ public abstract class AbstractMongoSessionConverterTest { assertThat(convertedSession.getMaxInactiveInterval()).isEqualTo(Duration.ofMinutes(30)); } + @Nullable MongoSession convertToSession(DBObject session) { return (MongoSession) getMongoSessionConverter().convert(session, TypeDescriptor.valueOf(DBObject.class), TypeDescriptor.valueOf(MongoSession.class)); } + @Nullable DBObject convertToDBObject(MongoSession session) { return (DBObject) getMongoSessionConverter().convert(session, TypeDescriptor.valueOf(MongoSession.class), TypeDescriptor.valueOf(DBObject.class)); diff --git a/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java b/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java index 6324a91..058517b 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java @@ -25,6 +25,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.core.serializer.DefaultDeserializer; import org.springframework.core.serializer.support.DeserializingConverter; import org.springframework.session.data.mongo.AbstractMongoSessionConverter; +import org.springframework.session.data.mongo.Assert; import org.springframework.session.data.mongo.JdkMongoSessionConverter; import org.springframework.util.ReflectionUtils; @@ -43,7 +44,7 @@ public abstract class AbstractClassLoaderTest extends AbstractITest { public void verifyContainerClassLoaderLoadedIntoConverter() { Field mongoSessionConverterField = ReflectionUtils.findField(sessionRepository.getClass(), "mongoSessionConverter"); - ReflectionUtils.makeAccessible(mongoSessionConverterField); + ReflectionUtils.makeAccessible(Assert.requireNonNull(mongoSessionConverterField, "mongoSessionConverter must not be null!")); AbstractMongoSessionConverter sessionConverter = (AbstractMongoSessionConverter) ReflectionUtils .getField(mongoSessionConverterField, this.sessionRepository); @@ -63,7 +64,7 @@ public abstract class AbstractClassLoaderTest extends AbstractITest { private static Object extractField(Class clazz, String fieldName, Object obj) { Field field = ReflectionUtils.findField(clazz, fieldName); - ReflectionUtils.makeAccessible(field); + ReflectionUtils.makeAccessible(Assert.requireNonNull(field, fieldName + " must not be null!")); return ReflectionUtils.getField(field, obj); } diff --git a/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java b/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java index 0a2c3e6..815e9f6 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/AbstractMongoRepositoryITest.java @@ -60,7 +60,7 @@ abstract public class AbstractMongoRepositoryITest extends AbstractITest { @Autowired protected MongoOperationsSessionRepository repository; @Test - public void saves() throws InterruptedException { + public void saves() { String username = "saves-" + System.currentTimeMillis(); diff --git a/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java b/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java index dbe98cf..6438419 100644 --- a/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java +++ b/src/test/java/org/springframework/session/data/mongo/integration/SessionEventRegistry.java @@ -24,8 +24,8 @@ import org.springframework.session.events.AbstractSessionEvent; public class SessionEventRegistry implements ApplicationListener { - private Map events = new HashMap(); - private Map locks = new HashMap(); + private Map events = new HashMap<>(); + private Map locks = new HashMap<>(); public void onApplicationEvent(AbstractSessionEvent event) { @@ -67,12 +67,7 @@ public class SessionEventRegistry implements ApplicationListener new Object()); } } }