Skip to content

Commit 7789d32

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
1 parent f3d0710 commit 7789d32

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
@@ -1202,23 +1202,21 @@ public static Stream<Field> streamFields(Class<?> clazz, Predicate<Field> predic
12021202
Preconditions.notNull(predicate, "Predicate must not be null");
12031203
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
12041204

1205-
return findAllFieldsInHierarchy(clazz, predicate, traversalMode).stream();
1205+
return findAllFieldsInHierarchy(clazz, traversalMode).stream().filter(predicate);
12061206
}
12071207

1208-
private static List<Field> findAllFieldsInHierarchy(Class<?> clazz, Predicate<Field> predicate,
1209-
HierarchyTraversalMode traversalMode) {
1210-
1208+
private static List<Field> findAllFieldsInHierarchy(Class<?> clazz, HierarchyTraversalMode traversalMode) {
12111209
Preconditions.notNull(clazz, "Class must not be null");
12121210
Preconditions.notNull(traversalMode, "HierarchyTraversalMode must not be null");
12131211

12141212
// @formatter:off
1215-
List<Field> localFields = getDeclaredFields(clazz, predicate).stream()
1213+
List<Field> localFields = getDeclaredFields(clazz).stream()
12161214
.filter(field -> !field.isSynthetic())
12171215
.collect(toList());
1218-
List<Field> superclassFields = getSuperclassFields(clazz, predicate, traversalMode).stream()
1216+
List<Field> superclassFields = getSuperclassFields(clazz, traversalMode).stream()
12191217
.filter(field -> !isFieldShadowedByLocalFields(field, localFields))
12201218
.collect(toList());
1221-
List<Field> interfaceFields = getInterfaceFields(clazz, predicate, traversalMode).stream()
1219+
List<Field> interfaceFields = getInterfaceFields(clazz, traversalMode).stream()
12221220
.filter(field -> !isFieldShadowedByLocalFields(field, localFields))
12231221
.collect(toList());
12241222
// @formatter:on
@@ -1481,18 +1479,18 @@ private static List<Method> findAllMethodsInHierarchy(Class<?> clazz, Predicate<
14811479

14821480
/**
14831481
* Custom alternative to {@link Class#getFields()} that sorts the fields
1484-
* which match the supplied predicate and converts them to a mutable list.
1482+
* and converts them to a mutable list.
14851483
*/
1486-
private static List<Field> getFields(Class<?> clazz, Predicate<Field> predicate) {
1487-
return toSortedMutableList(clazz.getFields(), predicate);
1484+
private static List<Field> getFields(Class<?> clazz) {
1485+
return toSortedMutableList(clazz.getFields());
14881486
}
14891487

14901488
/**
14911489
* Custom alternative to {@link Class#getDeclaredFields()} that sorts the
1492-
* fields which match the supplied predicate and converts them to a mutable list.
1490+
* fields and converts them to a mutable list.
14931491
*/
1494-
private static List<Field> getDeclaredFields(Class<?> clazz, Predicate<Field> predicate) {
1495-
return toSortedMutableList(clazz.getDeclaredFields(), predicate);
1492+
private static List<Field> getDeclaredFields(Class<?> clazz) {
1493+
return toSortedMutableList(clazz.getDeclaredFields());
14961494
}
14971495

14981496
/**
@@ -1556,10 +1554,9 @@ private static List<Method> getDefaultMethods(Class<?> clazz, Predicate<Method>
15561554
// @formatter:on
15571555
}
15581556

1559-
private static List<Field> toSortedMutableList(Field[] fields, Predicate<Field> predicate) {
1557+
private static List<Field> toSortedMutableList(Field[] fields) {
15601558
// @formatter:off
15611559
return Arrays.stream(fields)
1562-
.filter(predicate)
15631560
.sorted(ReflectionUtils::defaultFieldSorter)
15641561
// Use toCollection() instead of toList() to ensure list is mutable.
15651562
.collect(toCollection(ArrayList::new));
@@ -1628,15 +1625,13 @@ private static List<Method> getInterfaceMethods(Class<?> clazz, Predicate<Method
16281625
return allInterfaceMethods;
16291626
}
16301627

1631-
private static List<Field> getInterfaceFields(Class<?> clazz, Predicate<Field> predicate,
1632-
HierarchyTraversalMode traversalMode) {
1633-
1628+
private static List<Field> getInterfaceFields(Class<?> clazz, HierarchyTraversalMode traversalMode) {
16341629
List<Field> allInterfaceFields = new ArrayList<>();
16351630
for (Class<?> ifc : clazz.getInterfaces()) {
1636-
List<Field> localInterfaceFields = getFields(ifc, predicate);
1631+
List<Field> localInterfaceFields = getFields(ifc);
16371632

16381633
// @formatter:off
1639-
List<Field> superinterfaceFields = getInterfaceFields(ifc, predicate, traversalMode).stream()
1634+
List<Field> superinterfaceFields = getInterfaceFields(ifc, traversalMode).stream()
16401635
.filter(field -> !isFieldShadowedByLocalFields(field, localInterfaceFields))
16411636
.collect(toList());
16421637
// @formatter:on
@@ -1652,14 +1647,12 @@ private static List<Field> getInterfaceFields(Class<?> clazz, Predicate<Field> p
16521647
return allInterfaceFields;
16531648
}
16541649

1655-
private static List<Field> getSuperclassFields(Class<?> clazz, Predicate<Field> predicate,
1656-
HierarchyTraversalMode traversalMode) {
1657-
1650+
private static List<Field> getSuperclassFields(Class<?> clazz, HierarchyTraversalMode traversalMode) {
16581651
Class<?> superclass = clazz.getSuperclass();
16591652
if (!isSearchable(superclass)) {
16601653
return Collections.emptyList();
16611654
}
1662-
return findAllFieldsInHierarchy(superclass, predicate, traversalMode);
1655+
return findAllFieldsInHierarchy(superclass, traversalMode);
16631656
}
16641657

16651658
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;
@@ -1357,10 +1358,11 @@ void isGeneric() {
13571358
}
13581359

13591360
/**
1360-
* @see https://github.com/junit-team/junit5/issues/3532
1361+
* @see https://github.com/junit-team/junit5/issues/3553
13611362
*/
1363+
@Disabled("Until #3553 is resolved")
13621364
@Test
1363-
void findFieldsAppliesPredicateBeforeSearchingTypeHierarchy() throws Exception {
1365+
void findFieldsDoesNotAllowInstanceFieldToHideStaticField() throws Exception {
13641366
final String TEMP_DIR = "tempDir";
13651367
Class<?> superclass = SuperclassWithStaticPackagePrivateTempDirField.class;
13661368
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)