Skip to content

Commit 81bc3c5

Browse files
christophstroblmp911de
authored andcommitted
Disable tests on Java 16 that require class-based proxies.
Original pull request: #3687. Resolves #3656
1 parent 403f001 commit 81bc3c5

File tree

4 files changed

+24
-12
lines changed

4 files changed

+24
-12
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/mapping/MongoMappingContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void setFieldNamingStrategy(@Nullable FieldNamingStrategy fieldNamingStra
7171
@Override
7272
protected boolean shouldCreatePersistentEntityFor(TypeInformation<?> type) {
7373

74-
if(NullableWrapperConverters.supports(type.getType())) {
74+
if (NullableWrapperConverters.supports(type.getType())) {
7575
return false;
7676
}
7777

@@ -139,7 +139,7 @@ public MongoPersistentEntity<?> getPersistentEntity(MongoPersistentProperty pers
139139

140140
MongoPersistentEntity<?> entity = super.getPersistentEntity(persistentProperty);
141141

142-
if(entity == null || !persistentProperty.isUnwrapped()) {
142+
if (entity == null || !persistentProperty.isUnwrapped()) {
143143
return entity;
144144
}
145145

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/DbRefMappingMongoConverterUnitTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import org.bson.types.ObjectId;
3737
import org.junit.jupiter.api.BeforeEach;
3838
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.condition.DisabledForJreRange;
40+
import org.junit.jupiter.api.condition.JRE;
3941
import org.junit.jupiter.api.extension.ExtendWith;
4042
import org.mockito.Mock;
4143
import org.mockito.Mockito;
@@ -181,6 +183,7 @@ void lazyLoadingProxyForLazyDbRefOnInterface() {
181183
}
182184

183185
@Test // DATAMONGO-348
186+
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
184187
void lazyLoadingProxyForLazyDbRefOnConcreteCollection() {
185188

186189
String id = "42";
@@ -508,6 +511,7 @@ void shouldNotEagerlyResolveIdPropertyWithPropertyAccess() {
508511
}
509512

510513
@Test // DATAMONGO-1076
514+
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
511515
void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() throws Exception {
512516

513517
MongoPersistentEntity<?> entity = mappingContext
@@ -526,6 +530,7 @@ void shouldNotTriggerResolvingOfLazyLoadedProxyWhenFinalizeMethodIsInvoked() thr
526530
}
527531

528532
@Test // DATAMONGO-1194
533+
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
529534
void shouldBulkFetchListOfReferences() {
530535

531536
String id1 = "1";
@@ -576,6 +581,7 @@ void shouldBulkFetchSetOfReferencesForConstructorCreation() {
576581
}
577582

578583
@Test // DATAMONGO-1194
584+
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
579585
void shouldFallbackToOneByOneFetchingWhenElementsInListOfReferencesPointToDifferentCollections() {
580586

581587
String id1 = "1";

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/PersonRepositoryLazyLoadingIntegrationTests.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@
2222
import java.util.Arrays;
2323
import java.util.List;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
28-
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
27+
import org.junit.jupiter.api.condition.DisabledForJreRange;
28+
import org.junit.jupiter.api.condition.JRE;
29+
import org.junit.jupiter.api.extension.ExtendWith;
2930
import org.springframework.beans.factory.annotation.Autowired;
3031
import org.springframework.data.mongodb.core.MongoOperations;
3132
import org.springframework.test.context.ContextConfiguration;
32-
import org.springframework.test.context.junit4.SpringRunner;
33+
import org.springframework.test.context.junit.jupiter.SpringExtension;
3334

3435
/**
3536
* Integration test for {@link PersonRepository} for lazy loading support.
@@ -38,13 +39,13 @@
3839
* @author Oliver Gierke
3940
*/
4041
@ContextConfiguration(locations = "PersonRepositoryIntegrationTests-context.xml")
41-
@RunWith(SpringRunner.class)
42+
@ExtendWith(SpringExtension.class)
4243
public class PersonRepositoryLazyLoadingIntegrationTests {
4344

4445
@Autowired PersonRepository repository;
4546
@Autowired MongoOperations operations;
4647

47-
@Before
48+
@BeforeEach
4849
public void setUp() throws InterruptedException {
4950

5051
repository.deleteAll();
@@ -61,7 +62,6 @@ public void shouldLoadAssociationWithDbRefOnInterfaceAndLazyLoadingEnabled() thr
6162
Person person = new Person();
6263
person.setFirstname("Oliver");
6364
person.setFans(Arrays.asList(thomas));
64-
person.setRealFans(new ArrayList<User>(Arrays.asList(thomas)));
6565
repository.save(person);
6666

6767
Person oliver = repository.findById(person.id).get();
@@ -75,15 +75,15 @@ public void shouldLoadAssociationWithDbRefOnInterfaceAndLazyLoadingEnabled() thr
7575
}
7676

7777
@Test // DATAMONGO-348
78-
public void shouldLoadAssociationWithDbRefOnConcreteCollectionAndLazyLoadingEnabled() throws Exception {
78+
@DisabledForJreRange(min = JRE.JAVA_16, disabledReason = "Class Proxies for eg. ArrayList require to open java.util.")
79+
public void shouldLoadAssociationWithDbRefOnConcreteCollectionAndLazyLoadingEnabled() {
7980

8081
User thomas = new User();
8182
thomas.username = "Thomas";
8283
operations.save(thomas);
8384

8485
Person person = new Person();
8586
person.setFirstname("Oliver");
86-
person.setFans(Arrays.asList(thomas));
8787
person.setRealFans(new ArrayList<User>(Arrays.asList(thomas)));
8888
repository.save(person);
8989

src/main/asciidoc/reference/document-references.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ TIP: Lazily loaded ``DBRef``s can be hard to debug.
4949
Make sure tooling does not accidentally trigger proxy resolution by e.g. calling `toString()` or some inline debug rendering invoking property getters.
5050
Please consider to enable _trace_ logging for `org.springframework.data.mongodb.core.convert.DefaultDbRefResolver` to gain insight on `DBRef` resolution.
5151

52+
CAUTION: Lazy loading may require class proxies, that in turn, might need access to jdk internals, that are not open, starting with Java 16+, due to https://openjdk.java.net/jeps/396[JEP 396: Strongly Encapsulate JDK Internals by Default].
53+
For those cases please consider falling back to an interface type (eg. switch from `ArrayList` to `List`) or provide the required `--add-opens` argument.
54+
5255
[[mapping-usage.document-references]]
5356
=== Using Document References
5457

@@ -136,6 +139,9 @@ Result order of `Collection` like properties is restored based on the used looku
136139
| Resolves properties eagerly by default.
137140
|===
138141

142+
CAUTION: Lazy loading may require class proxies, that in turn, might need access to jdk internals, that are not open, starting with Java 16+, due to https://openjdk.java.net/jeps/396[JEP 396: Strongly Encapsulate JDK Internals by Default].
143+
For those cases please consider falling back to an interface type (eg. switch from `ArrayList` to `List`) or provide the required `--add-opens` argument.
144+
139145
`@DocumentReference(lookup)` allows defining filter queries that can be different from the `_id` field and therefore offer a flexible way of defining references between entities as demonstrated in the sample below, where the `Publisher` of a book is referenced by its acronym instead of the internal `id`.
140146

141147
====

0 commit comments

Comments
 (0)