Skip to content

Commit e77fb77

Browse files
committed
Use standard Spring utils in MongoDB module
This commit replaces usages of custom assert utility class with standard one from Spring Framework, and removes the custom utility. See gh-2170
1 parent 009cb5b commit e77fb77

File tree

4 files changed

+12
-50
lines changed

4 files changed

+12
-50
lines changed

spring-session-data-mongodb/src/integration-test/java/org/springframework/session/data/mongo/integration/AbstractClassLoaderTest.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018 the original author or authors.
2+
* Copyright 2014-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.
@@ -26,7 +26,6 @@
2626
import org.springframework.core.serializer.DefaultDeserializer;
2727
import org.springframework.core.serializer.support.DeserializingConverter;
2828
import org.springframework.session.data.mongo.AbstractMongoSessionConverter;
29-
import org.springframework.session.data.mongo.Assert;
3029
import org.springframework.session.data.mongo.JdkMongoSessionConverter;
3130
import org.springframework.util.ReflectionUtils;
3231

@@ -49,8 +48,7 @@ void verifyContainerClassLoaderLoadedIntoConverter() {
4948

5049
Field mongoSessionConverterField = ReflectionUtils.findField(this.sessionRepository.getClass(),
5150
"mongoSessionConverter");
52-
ReflectionUtils.makeAccessible(
53-
Assert.requireNonNull(mongoSessionConverterField, "mongoSessionConverter must not be null!"));
51+
ReflectionUtils.makeAccessible(mongoSessionConverterField);
5452
AbstractMongoSessionConverter sessionConverter = (AbstractMongoSessionConverter) ReflectionUtils
5553
.getField(mongoSessionConverterField, this.sessionRepository);
5654

@@ -70,7 +68,7 @@ void verifyContainerClassLoaderLoadedIntoConverter() {
7068
private static Object extractField(Class<?> clazz, String fieldName, Object obj) {
7169

7270
Field field = ReflectionUtils.findField(clazz, fieldName);
73-
ReflectionUtils.makeAccessible(Assert.requireNonNull(field, fieldName + " must not be null!"));
71+
ReflectionUtils.makeAccessible(field);
7472
return ReflectionUtils.getField(field, obj);
7573
}
7674

spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/AbstractMongoSessionConverter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2016 the original author or authors.
2+
* Copyright 2014-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.
@@ -36,6 +36,7 @@
3636
import org.springframework.session.FindByIndexNameSessionRepository;
3737
import org.springframework.session.IndexResolver;
3838
import org.springframework.session.PrincipalNameIndexResolver;
39+
import org.springframework.util.Assert;
3940

4041
/**
4142
* Base class for serializing and deserializing session objects. To create custom
@@ -123,7 +124,8 @@ else if (Document.class.isAssignableFrom(sourceType.getType())) {
123124
protected abstract MongoSession convert(Document sessionWrapper);
124125

125126
public void setIndexResolver(IndexResolver<MongoSession> indexResolver) {
126-
this.indexResolver = Assert.requireNonNull(indexResolver, "indexResolver must not be null!");
127+
Assert.notNull(indexResolver, "indexResolver must not be null");
128+
this.indexResolver = indexResolver;
127129
}
128130

129131
}

spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/Assert.java

Lines changed: 0 additions & 40 deletions
This file was deleted.

spring-session-data-mongodb/src/main/java/org/springframework/session/data/mongo/MongoIndexedSessionRepository.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Optional;
2323
import java.util.stream.Collectors;
2424

25+
import com.mongodb.DBObject;
2526
import org.apache.commons.logging.Log;
2627
import org.apache.commons.logging.LogFactory;
2728
import org.bson.Document;
@@ -38,6 +39,7 @@
3839
import org.springframework.session.events.SessionCreatedEvent;
3940
import org.springframework.session.events.SessionDeletedEvent;
4041
import org.springframework.session.events.SessionExpiredEvent;
42+
import org.springframework.util.Assert;
4143

4244
/**
4345
* Session repository implementation which stores sessions in Mongo. Uses
@@ -97,9 +99,9 @@ public MongoSession createSession() {
9799

98100
@Override
99101
public void save(MongoSession session) {
100-
this.mongoOperations
101-
.save(Assert.requireNonNull(MongoSessionUtils.convertToDBObject(this.mongoSessionConverter, session),
102-
"convertToDBObject must not null!"), this.collectionName);
102+
DBObject dbObject = MongoSessionUtils.convertToDBObject(this.mongoSessionConverter, session);
103+
Assert.notNull(dbObject, "dbObject must not be null");
104+
this.mongoOperations.save(dbObject, this.collectionName);
103105
}
104106

105107
@Override

0 commit comments

Comments
 (0)