-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Regression: assertThrows() ThrowingSupplier variants break existing code #1576
Comments
Slated for 5.3.1 |
@junit-team/junit-lambda, I've added the "team discussion" label in order for us to address this as soon as possible. |
Sorry :( And thanks for all the details about the specific problem case. As @kevinb9n said during the initial overload problems:
That would be my inclination, as well: If users have to switch to |
We should also consider to keep the Only method references to overloaded methods that return Did you encounter that problem in your test suites? Am I the only one who had to apply a workaround in his test code? (I assume, I am...) |
I'll find out how often this comes up in our code and report back. (I was waiting for junit-team/junit4#1537 to be resolved before using the latest version of the patch.) |
Thanks, @cushon |
That's of course also an option, one of three I suppose. I'll update the Proposals section of this issue. |
That's also worth considering. |
OK... We now have three proposals to choose from. |
Food for thought: Another downside to keeping it "as is" is that user code would also break (in the future) if it uses a method reference for a void-returning method now that later gets overloaded. And... that would be totally out of JUnit's control. |
I'm not sure if you're aware: The Eclipse IDE project seems to make upgrading its JUnit support (from currently 5.1) to 5.3(.1) dependent on this issue. |
No, we were not aware of that potential holdup in Eclipse IDE. So, thank you for bringing it to our attention! |
Team Decision:
|
FYI: I updated the Deliverables according to the team decision. |
in progress |
JUnit Jupiter 5.3.0 introduced new variants of `assertThrows()` that accept `ThrowingSupplier` arguments instead of `Executable` (see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with a `void` return type. Consequently, this was a breaking change. Note that overloaded methods with non-void return types are not affected. For example, even though `java.util.concurrent.Future` has two `get(...)` methods, it still can be used as a method reference as `future::get` without suffering from issues with type inference since such a method can always properly be inferred to be a `ThrowingSupplier`. This commit fixes the breaking change by removing all variants of `assertThrows` that accept a `ThrowingSupplier`. In addition, this commit reverts the related changes to `ThrowingSupplier` (i.e., it no longer implements `Executable` via a `default` interface method). Since the breaking change brought it to our attention that issues can arise when overloading methods that differ only by the functional interface they accept, we noticed that some restrictions apply to the use of method references for the existing overloaded `assertDoesNotThrow()` variants. This commit therefore also adds notes to the JavaDoc for the affected methods. Issue: #1576
JUnit Jupiter 5.3.0 introduced new variants of `assertThrows()` that accept `ThrowingSupplier` arguments instead of `Executable` (see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with a `void` return type. Consequently, this was a breaking change. Note that overloaded methods with non-void return types are not affected. For example, even though `java.util.concurrent.Future` has two `get(...)` methods, it still can be used as a method reference as `future::get` without suffering from issues with type inference since such a method can always properly be inferred to be a `ThrowingSupplier`. This commit fixes the breaking change by removing all variants of `assertThrows` that accept a `ThrowingSupplier`. In addition, this commit reverts the related changes to `ThrowingSupplier` (i.e., it no longer implements `Executable` via a `default` interface method). Since the breaking change brought it to our attention that issues can arise when overloading methods that differ only by the functional interface they accept, we noticed that some restrictions apply to the use of method references for the existing overloaded `assertDoesNotThrow()` variants. This commit therefore also adds notes to the JavaDoc for the affected methods. Issue: #1576
JUnit Jupiter 5.3.0 introduced new variants of `assertThrows()` that accept `ThrowingSupplier` arguments instead of `Executable` (see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with a `void` return type. Consequently, this was a breaking change. Note that overloaded methods with non-void return types are not affected. For example, even though `java.util.concurrent.Future` has two `get(...)` methods, it still can be used as a method reference as `future::get` without suffering from issues with type inference since such a method can always properly be inferred to be a `ThrowingSupplier`. This commit fixes the breaking change by removing all variants of `assertThrows` that accept a `ThrowingSupplier`. In addition, this commit reverts the related changes to `ThrowingSupplier` (i.e., it no longer implements `Executable` via a `default` interface method). Issue: #1576
JUnit Jupiter 5.3.0 introduced new variants of `assertThrows()` that accept `ThrowingSupplier` arguments instead of `Executable` (see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with a `void` return type. Consequently, this was a breaking change. Note that overloaded methods with non-void return types are not affected. For example, even though `java.util.concurrent.Future` has two `get(...)` methods, it still can be used as a method reference as `future::get` without suffering from issues with type inference since such a method can always properly be inferred to be a `ThrowingSupplier`. This commit fixes the breaking change by removing all variants of `assertThrows` that accept a `ThrowingSupplier`. In addition, this commit reverts the related changes to `ThrowingSupplier` (i.e., it no longer implements `Executable` via a `default` interface method). Issue: #1576
JUnit Jupiter 5.3.0 introduced new variants of `assertThrows()` that accept `ThrowingSupplier` arguments instead of `Executable` (see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with a `void` return type. Consequently, this was a breaking change. Note that overloaded methods with non-void return types are not affected. For example, even though `java.util.concurrent.Future` has two `get(...)` methods, it still can be used as a method reference as `future::get` without suffering from issues with type inference since such a method can always properly be inferred to be a `ThrowingSupplier`. This commit fixes the breaking change by removing all variants of `assertThrows` that accept a `ThrowingSupplier`. In addition, this commit reverts the related changes to `ThrowingSupplier` (i.e., it no longer implements `Executable` via a `default` interface method). Issue: #1576
This has been fixed in 2e496ca. Note, however, that this work has not yet been backported to the soon-to-be-created |
JUnit Jupiter 5.3.0 introduced new variants of `assertThrows()` that accept `ThrowingSupplier` arguments instead of `Executable` (see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with a `void` return type. Consequently, this was a breaking change. Note that overloaded methods with non-void return types are not affected. For example, even though `java.util.concurrent.Future` has two `get(...)` methods, it still can be used as a method reference as `future::get` without suffering from issues with type inference since such a method can always properly be inferred to be a `ThrowingSupplier`. This commit fixes the breaking change by removing all variants of `assertThrows` that accept a `ThrowingSupplier`. In addition, this commit reverts the related changes to `ThrowingSupplier` (i.e., it no longer implements `Executable` via a `default` interface method). Issue: #1576
Backported to the |
I could not make it work with |
Overview
JUnit Jupiter 5.3.0 introduced new variants of
assertThrows()
that acceptThrowingSupplier
arguments instead ofExecutable
(see #1394). However, this change prevents existing code from compiling against Jupiter 5.3.0 if the code in question used a method reference for an overloaded method with avoid
return type.Note that overloaded methods with non-void return types are not affected. For example, even though
java.util.concurrent.Future
has twoget(...)
methods, it still can be used as a method reference asfuture::get
without suffering from issues with type inference since such a method can always properly be inferred to be aThrowingSupplier
.Example
Note that
java.lang.Object
has three overloaded variants of itswait()
method. Thus, the following example compiled against Jupiter 5.2.0 but fails to compile against Jupiter 5.3.0.Workarounds
The following two workarounds allow affected code to compile against Jupiter 5.3.0; however, this obviously requires a manual change to existing code which is an unacceptable breaking change.
Analysis
Given the following test class, the code compiles "as is", but the invocation of
assertThrows(Exception.class, object::wait)
will fail to compile if you uncomment theassertThrows()
variant that accepts aThrowingSupplier
.Proposal
In other to avoid issues with type inference for overloaded methods used as method references, we should revert the changes to all existing
assertThrows()
methods and introduce newassertThrowsXyz()
variants that accept aThrowingSupplier
.This will enforce that all existing code that invokes
assertThrows()
will use anExecutable
, and all new code compiled against the newassertThrowsXyz()
variants will use aThrowingSupplier
.What
Xyz
should be is up for debate.Related Issues
Deliverables
assertThrows
that accept aThrowingSupplier
ThrowingSupplier
assertDoesNotThrow
(and document workarounds if necessary)5.3.1
branch.The text was updated successfully, but these errors were encountered: