Skip to content

Commit 85ec2fc

Browse files
committed
Revert "Apply field predicate before searching type hierarchy"
This commit reverts the functional changes from commit f30a8d5 and disables the associated tests for the time being. See #3532 See #3553 Closes #3638 (cherry picked from commit 7789d32)
1 parent 6209006 commit 85ec2fc

File tree

6 files changed

+52
-37
lines changed

6 files changed

+52
-37
lines changed

documentation/src/docs/asciidoc/release-notes/release-notes-5.10.2.adoc

+25-7
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,52 @@
33

44
*Date of Release:* ❓
55

6-
*Scope:* minor bug fixes since 5.10.1.
6+
*Scope:* minor bug fixes and changes since 5.10.1.
77

88
For a complete list of all _closed_ issues and pull requests for this release, consult the
9-
link:{junit5-repo}+/milestone/73?closed=1+[5.10.2] milestone page in the
10-
JUnit repository on GitHub.
9+
link:{junit5-repo}+/milestone/73?closed=1+[5.10.2] milestone page in the JUnit repository
10+
on GitHub.
1111

1212

1313
[[release-notes-5.10.2-junit-platform]]
1414
=== JUnit Platform
1515

1616
==== Bug Fixes
1717

18-
* Allow `junit-platform-launcher` to be used as a Java module when
18+
* The `junit-platform-launcher` may now be used as a Java module when
1919
`junit.platform.launcher.interceptors.enabled` is set to `true`.
20-
- See link:https://github.com/junit-team/junit5/issues/3561[issue 3561] for details.
20+
- See issue link:https://github.com/junit-team/junit5/issues/3561[#3561] for details.
21+
22+
==== Deprecations and Breaking Changes
23+
24+
* Field predicates are no longer applied eagerly while searching the type hierarchy. This
25+
reverts changes made in 5.10.1 that affected `findFields(...)` and `streamFields(...)`
26+
in `ReflectionSupport` as well as `findAnnotatedFields(...)` and
27+
`findAnnotatedFieldValues(...)` in `AnnotationSupport`.
28+
- See issues link:https://github.com/junit-team/junit5/issues/3638[#3638] and
29+
link:https://github.com/junit-team/junit5/issues/3553[#3553] for details.
2130

2231

2332
[[release-notes-5.10.2-junit-jupiter]]
2433
=== JUnit Jupiter
2534

2635
==== Bug Fixes
2736

28-
* _none so far_
37+
* ❓
38+
39+
==== Deprecations and Breaking Changes
40+
41+
* A package-private static field annotated with `@TempDir` is once again _shadowed_ by a
42+
non-static field annotated with `@TempDir` when the non-static field resides in a
43+
different package and has the same name as the static field. This reverts changes made
44+
in 5.10.1.
45+
- See issues link:https://github.com/junit-team/junit5/issues/3638[#3638] and
46+
link:https://github.com/junit-team/junit5/issues/3553[#3553] for details.
2947

3048

3149
[[release-notes-5.10.2-junit-vintage]]
3250
=== JUnit Vintage
3351

3452
==== Bug Fixes
3553

36-
* _none so far_
54+
*

junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java

+17-24
Original file line numberDiff line numberDiff line change
@@ -1253,23 +1253,21 @@ public static Stream<Field> streamFields(Class<?> clazz, Predicate<Field> predic
12531253
Preconditions.notNull(predicate, "Predicate must not be null");
12541254
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
12551255

1256-
return findAllFieldsInHierarchy(clazz, predicate, traversalMode).stream();
1256+
return findAllFieldsInHierarchy(clazz, traversalMode).stream().filter(predicate);
12571257
}
12581258

1259-
private static List<Field> findAllFieldsInHierarchy(Class<?> clazz, Predicate<Field> predicate,
1260-
HierarchyTraversalMode traversalMode) {
1261-
1259+
private static List<Field> findAllFieldsInHierarchy(Class<?> clazz, HierarchyTraversalMode traversalMode) {
12621260
Preconditions.notNull(clazz, "Class must not be null");
12631261
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
12641262

12651263
// @formatter:off
1266-
List<Field> localFields = getDeclaredFields(clazz, predicate).stream()
1264+
List<Field> localFields = getDeclaredFields(clazz).stream()
12671265
.filter(field -> !field.isSynthetic())
12681266
.collect(toList());
1269-
List<Field> superclassFields = getSuperclassFields(clazz, predicate, traversalMode).stream()
1267+
List<Field> superclassFields = getSuperclassFields(clazz, traversalMode).stream()
12701268
.filter(field -> !isFieldShadowedByLocalFields(field, localFields))
12711269
.collect(toList());
1272-
List<Field> interfaceFields = getInterfaceFields(clazz, predicate, traversalMode).stream()
1270+
List<Field> interfaceFields = getInterfaceFields(clazz, traversalMode).stream()
12731271
.filter(field -> !isFieldShadowedByLocalFields(field, localFields))
12741272
.collect(toList());
12751273
// @formatter:on
@@ -1532,18 +1530,18 @@ private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, Predicate<
15321530

15331531
/**
15341532
* Custom alternative to {@link Class#getFields()} that sorts the fields
1535-
* which match the supplied predicate and converts them to a mutable list.
1533+
* and converts them to a mutable list.
15361534
*/
1537-
private static List<Field> getFields(Class<?> clazz, Predicate<Field> predicate) {
1538-
return toSortedMutableList(clazz.getFields(), predicate);
1535+
private static List<Field> getFields(Class<?> clazz) {
1536+
return toSortedMutableList(clazz.getFields());
15391537
}
15401538

15411539
/**
15421540
* Custom alternative to {@link Class#getDeclaredFields()} that sorts the
1543-
* fields which match the supplied predicate and converts them to a mutable list.
1541+
* fields and converts them to a mutable list.
15441542
*/
1545-
private static List<Field> getDeclaredFields(Class<?> clazz, Predicate<Field> predicate) {
1546-
return toSortedMutableList(clazz.getDeclaredFields(), predicate);
1543+
private static List<Field> getDeclaredFields(Class<?> clazz) {
1544+
return toSortedMutableList(clazz.getDeclaredFields());
15471545
}
15481546

15491547
/**
@@ -1607,10 +1605,9 @@ private static List<Method> getDefaultMethods(Class<?> clazz, Predicate<Method>
16071605
// @formatter:on
16081606
}
16091607

1610-
private static List<Field> toSortedMutableList(Field[] fields, Predicate<Field> predicate) {
1608+
private static List<Field> toSortedMutableList(Field[] fields) {
16111609
// @formatter:off
16121610
return Arrays.stream(fields)
1613-
.filter(predicate)
16141611
.sorted(ReflectionUtils::defaultFieldSorter)
16151612
// Use toCollection() instead of toList() to ensure list is mutable.
16161613
.collect(toCollection(ArrayList::new));
@@ -1679,15 +1676,13 @@ private static List<Method> getInterfaceMethods(Class<?> clazz, Predicate<Method
16791676
return allInterfaceMethods;
16801677
}
16811678

1682-
private static List<Field> getInterfaceFields(Class<?> clazz, Predicate<Field> predicate,
1683-
HierarchyTraversalMode traversalMode) {
1684-
1679+
private static List<Field> getInterfaceFields(Class<?> clazz, HierarchyTraversalMode traversalMode) {
16851680
List<Field> allInterfaceFields = new ArrayList<>();
16861681
for (Class<?> ifc : clazz.getInterfaces()) {
1687-
List<Field> localInterfaceFields = getFields(ifc, predicate);
1682+
List<Field> localInterfaceFields = getFields(ifc);
16881683

16891684
// @formatter:off
1690-
List<Field> superinterfaceFields = getInterfaceFields(ifc, predicate, traversalMode).stream()
1685+
List<Field> superinterfaceFields = getInterfaceFields(ifc, traversalMode).stream()
16911686
.filter(field -> !isFieldShadowedByLocalFields(field, localInterfaceFields))
16921687
.collect(toList());
16931688
// @formatter:on
@@ -1703,14 +1698,12 @@ private static List<Field> getInterfaceFields(Class<?> clazz, Predicate<Field> p
17031698
return allInterfaceFields;
17041699
}
17051700

1706-
private static List<Field> getSuperclassFields(Class<?> clazz, Predicate<Field> predicate,
1707-
HierarchyTraversalMode traversalMode) {
1708-
1701+
private static List<Field> getSuperclassFields(Class<?> clazz, HierarchyTraversalMode traversalMode) {
17091702
Class<?> superclass = clazz.getSuperclass();
17101703
if (!isSearchable(superclass)) {
17111704
return Collections.emptyList();
17121705
}
1713-
return findAllFieldsInHierarchy(superclass, predicate, traversalMode);
1706+
return findAllFieldsInHierarchy(superclass, traversalMode);
17141707
}
17151708

17161709
private static boolean isFieldShadowedByLocalFields(Field field, List<Field> localFields) {

platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import org.junit.jupiter.api.BeforeAll;
4646
import org.junit.jupiter.api.BeforeEach;
47+
import org.junit.jupiter.api.Disabled;
4748
import org.junit.jupiter.api.Test;
4849
import org.junit.platform.commons.PreconditionViolationException;
4950
import org.junit.platform.commons.util.pkg1.ClassLevelDir;
@@ -509,10 +510,11 @@ private List<Field> findShadowingAnnotatedFields(Class<? extends Annotation> ann
509510
}
510511

511512
/**
512-
* @see https://github.com/junit-team/junit5/issues/3532
513+
* @see https://github.com/junit-team/junit5/issues/3553
513514
*/
515+
@Disabled("Until #3553 is resolved")
514516
@Test
515-
void findAnnotatedFieldsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception {
517+
void findAnnotatedFieldsDoesNotAllowInstanceFieldToHideStaticField() throws Exception {
516518
final String TEMP_DIR = "tempDir";
517519
Class<?> superclass = SuperclassWithStaticPackagePrivateTempDirField.class;
518520
Field staticField = superclass.getDeclaredField(TEMP_DIR);

platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsTests.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.stream.IntStream;
5353
import java.util.stream.Stream;
5454

55+
import org.junit.jupiter.api.Disabled;
5556
import org.junit.jupiter.api.Nested;
5657
import org.junit.jupiter.api.Test;
5758
import org.junit.jupiter.api.fixtures.TrackLogRecords;
@@ -1383,10 +1384,11 @@ void isGeneric() {
13831384
}
13841385

13851386
/**
1386-
* @see https://github.com/junit-team/junit5/issues/3532
1387+
* @see https://github.com/junit-team/junit5/issues/3553
13871388
*/
1389+
@Disabled("Until #3553 is resolved")
13881390
@Test
1389-
void findFieldsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception {
1391+
void findFieldsDoesNotAllowInstanceFieldToHideStaticField() throws Exception {
13901392
final String TEMP_DIR = "tempDir";
13911393
Class<?> superclass = SuperclassWithStaticPackagePrivateTempDirField.class;
13921394
Field staticField = superclass.getDeclaredField(TEMP_DIR);

platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/SuperclassWithStaticPackagePrivateTempDirField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import java.nio.file.Path;
1414

1515
/**
16-
* @see https://github.com/junit-team/junit5/issues/3532
16+
* @see https://github.com/junit-team/junit5/issues/3553
1717
*/
1818
public class SuperclassWithStaticPackagePrivateTempDirField {
1919

platform-tests/src/test/java/org/junit/platform/commons/util/pkg1/subpkg/SubclassWithNonStaticPackagePrivateTempDirField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import org.junit.platform.commons.util.pkg1.SuperclassWithStaticPackagePrivateTempDirField;
1717

1818
/**
19-
* @see https://github.com/junit-team/junit5/issues/3532
19+
* @see https://github.com/junit-team/junit5/issues/3553
2020
*/
2121
public class SubclassWithNonStaticPackagePrivateTempDirField extends SuperclassWithStaticPackagePrivateTempDirField {
2222

0 commit comments

Comments
 (0)