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

ExternalResource: declare after() to throw Exception #1421

Merged

Conversation

alb-i986
Copy link
Contributor

So that clients don't have to try-catch-and-rethrow explicitly checked exceptions.

You may not be happy with changing the signature, though :(

So that clients don't have to try-catch-and-rethrow explicitly checked exceptions.
*/
protected void after() {
protected void after() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why Exception instead of Throwable like we did for before()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because AFAIK rarely methods throw Throwable, it's more likely they throw Exception, e.g. AutoCloseable#close.
But ya, we should probably make it more generic and throw Throwable.
Do you want me to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it's rare for methods to throw Throwable, when you call a method using reflection you often handle the InvocationTargetException by throwing the cause (a Throwable). That's why Statement.evaluate() is declared to throw Throwable.

I don't think it harms anything to have the method declared to throw Throwable. The calling code catches Throwable and subclasses of ExternalResource can override the method to throw a different exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that closing a resource usually involves doing reflection or anything that throws Throwable, but anyway yeah, it's harmless, so I'll do.

Copy link
Member

@kcooney kcooney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I will wait for another maintainer to review this before we squash and merge.

@kcooney kcooney merged commit cebbf5e into junit-team:master Feb 27, 2017
@kcooney
Copy link
Member

kcooney commented Feb 27, 2017

Merged. @alb-i986 could you please update the release notes?

@alb-i986
Copy link
Contributor Author

alb-i986 commented Mar 1, 2017

Release notes updated.

Cheers

@alb-i986 alb-i986 deleted the ExternalResource-after-throws-Exception branch March 1, 2017 22:12
sebasjm pushed a commit to sebasjm/junit4 that referenced this pull request Mar 11, 2018
This allows clients to call methods that throw checked exceptions without having to catch and wrap checked exceptions.
@kcooney
Copy link
Member

kcooney commented Mar 28, 2019

@marcphilipp This breaks code that extends ExternalResource, overrides after(), and calls super.after() in after(). I think we should roll it back.

@kcooney kcooney mentioned this pull request Mar 29, 2019
@marcphilipp
Copy link
Member

Agreed!

@kcooney Do you have time to do so?

@kcooney
Copy link
Member

kcooney commented Apr 3, 2019

@marcphilipp I thought I might have time but apparently not 🙁

panchenko added a commit to panchenko/junit that referenced this pull request Apr 3, 2019
panchenko added a commit to panchenko/junit that referenced this pull request Apr 4, 2019
…eam#1421)"

Revert commit cebbf5e.
It breaks code that extends ExternalResource,
overrides after() and calls super.after() in after().
marcphilipp pushed a commit that referenced this pull request Apr 4, 2019
Revert commit cebbf5e.
It breaks code that extends ExternalResource,
overrides after() and calls super.after() in after().
aristotle0x01 pushed a commit to aristotle0x01/junit4 that referenced this pull request Jun 27, 2022
This allows clients to call methods that throw checked exceptions without having to catch and wrap checked exceptions.
aristotle0x01 pushed a commit to aristotle0x01/junit4 that referenced this pull request Jun 27, 2022
…eam#1421)"

Revert commit cebbf5e.
It breaks code that extends ExternalResource,
overrides after() and calls super.after() in after().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants