-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Backwards wildcard bound on ExpectedException.expectCause() #1073
Comments
I don't see why the current API would result in class cast exceptions. Note that Can you give an example of code that compiles that uses It's true that developers would get a compile time error with the current API when trying to pass a I can see someone passing a subclass of |
Ah you're right that And yeah, my suggestion would break I only noticed this by trying |
The signature of |
Turns out I was wrong... the signature isn't broken. The two methods are used for different purposes: So I'm actually not sure there is a good reason to use Given that, and given the signature of |
Changing
isn't caught by the compiler anymore. IMHO in a type checked language like Java the method signatures shouldn't only check that the arguments technically work for what is done inside the method but also that the semantics are okay (as far as that's possible). |
@UrsMetz that is true, bit that also holds true for Again, if we wrote the API today I would not suggest We may be willing to "correct" the generics in JUnit5 (because users will be told to expect some changes, and we will likely still make high-impact big fixes to 4.x after 5.0 is released). That all being said, a lambda-based API for making assertions on exceptions is the long-term plan. |
I agree that |
Note that we are considering removing our Hamcrest dependencies, so you might want to file this bug against the java-hamcrest project (https://github.com/hamcrest/hamcrest-junit). @npryce I would suggest that java-hamcrest 1.x.x.x should use |
The previous generics (Matcher<? extends Throwable>) would not allow you do use matchers on Object, like notNullValue(). Fixes junit-team#1073
The previous generics (Matcher<? extends Throwable>) would not allow you do use matchers on Object, like notNullValue(). Fixes #1073
The previous generics (Matcher<? extends Throwable>) would not allow you do use matchers on Object, like notNullValue(). Fixes junit-team#1073
The previous generics (Matcher<? extends Throwable>) would not allow you do use matchers on Object, like notNullValue(). Fixes junit-team#1073
The signature of that method is
expectCause(Matcher<? extends Throwable> expectedCause)
. This acceptsMatcher<RuntimeException>
, but possibly passes it other types such asIOException
, resulting in heap pollution.On the other hand, it forbids
Matcher<Object>
, even though that would be completely type-safe.The type should be
Matcher<? super Throwable>
instead.The text was updated successfully, but these errors were encountered: