Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detecting cycles in inner class hierarchies throws exceptions even for classes not marked as @Nested #2249

Closed
chavan77me opened this issue Apr 7, 2020 · 2 comments

Comments

@chavan77me
Copy link

chavan77me commented Apr 7, 2020

Upgrading to JUnit 5.6 is breaking a unit test I have.

private class MySillyClosure(...) extends Closure<RetryStrategy>(...) { 
    @override
    RetryStrategy call(...) { return MyStrategy() } 
}

This class is defined in my test suite and the recursive check fails even though I have not marked any of these classes as @Nested.

I think this is the suspect code:

/~https://github.com/junit-team/junit5/blob/master/junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/discovery/predicates/IsTestClassWithTests.java#L46

/~https://github.com/junit-team/junit5/blob/master/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ReflectionUtils.java#L1007-L1008

Notice that the code looks for all nested classes (and asserts on finding a cycle) before attempting to filter out using the predicate for @Nested. Therefore any class that has this inner inheritance (in my case Groovy Closure and WriteableClosure) is causing an error even if they are not marked as @Nested.

For reference, here is the closure code and its inner class:

/~https://github.com/groovy/groovy-core/blob/master/src/main/groovy/lang/Closure.java#L847

Is there a way for me to disable this recursion check?

@sbrannen
Copy link
Member

sbrannen commented Apr 7, 2020

I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference.

@sbrannen
Copy link
Member

sbrannen commented Apr 7, 2020

Is there a way for me to disable this recursion check?

No. There is unfortunately no way to disable the cycle detection, but we'll look into fixing the issue.

Thanks for bringing this to our attention!

@sbrannen sbrannen self-assigned this Apr 7, 2020
@sbrannen sbrannen added this to the 5.7 M1 milestone Apr 7, 2020
@marcphilipp marcphilipp modified the milestones: 5.7 M1, 5.6.2 Apr 7, 2020
sbrannen added a commit that referenced this issue Apr 9, 2020
JUnit 5.6 introduced inner class cycle detection in
ReflectionSupport.findNestedClasses() (see #2039). Unfortunately, the
cycle detection introduced a regression for test classes that contain
classes with inner class cycles when those inner classes do not match
the predicate supplied to findNestedClasses() (e.g., "is annotated with
@nested"). Consequently, an exception is thrown for any inner class
cycled detected, even if the cycle would not adversely affect test
discovery or execution.

This commit fixes this regression by avoiding inner class cycle
detection for candidate classes that do match the predicate. For
example, within JUnit Jupiter inner class cycle detection is now only
performed for inner classes annotated with @nested.

Fixes #2249
sbrannen added a commit that referenced this issue Apr 9, 2020
JUnit 5.6 introduced inner class cycle detection in
ReflectionSupport.findNestedClasses() (see #2039). Unfortunately, the
cycle detection introduced a regression for test classes that contain
classes with inner class cycles when those inner classes do not match
the predicate supplied to findNestedClasses() (e.g., "is annotated with
@nested"). Consequently, an exception is thrown for any inner class
cycled detected, even if the cycle would not adversely affect test
discovery or execution.

This commit fixes this regression by avoiding inner class cycle
detection for candidate classes that do match the predicate. For
example, within JUnit Jupiter inner class cycle detection is now only
performed for inner classes annotated with @nested.

Fixes #2249
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants