Skip to content

WebConnection(Wrapper): throw a more specific IOException from close() that does not include InterruptedException - #59

Merged
rbri merged 1 commit into
HtmlUnit:masterfrom
lestephane:autocloseable-warning
Jul 11, 2019
Merged

WebConnection(Wrapper): throw a more specific IOException from close() that does not include InterruptedException#59
rbri merged 1 commit into
HtmlUnit:masterfrom
lestephane:autocloseable-warning

Conversation

@lestephane

@lestephane lestephane commented Jul 9, 2019

Copy link
Copy Markdown

🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥
NOTE: THIS WILL BREAK COMPILATION FOR ALL USERS OF THE LIBRARY
THAT HAVE BEEN CATCHING THE MORE GENERIC EXCEPTION SO FAR.
🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥 🔥

I defined my own subclass of WebConnectionWrapper to wrap a WebConnection, and got the warning

Warning:(91, 81) java: auto-closeable resource <anonymous com.gargoylesoftware.htmlunit.util.WebConnectionWrapper> has a member method close() that could throw InterruptedException
Error:java: warnings found and -Werror specified

AutoCloseable javadoc says

* <p>While this interface method is declared to throw {@code
* Exception}, implementers are <em>strongly</em> encouraged to
* declare concrete implementations of the {@code close} method to
* throw more specific exceptions, or to throw no exception at all
* if the close operation cannot fail.

* <p><em>Implementers of this interface are also strongly advised
* to not have the {@code close} method throw {@link
* InterruptedException}.</em>

Suggested solution is to throw the more specific exception IOException

  • @Override void close() throws IOException; in WebConnectionWrapper
  • @Override void close() throws IOException; in WebConnection

@lestephane lestephane changed the title throw a more specific exception that does not include InterruptedException WebConnection(Wrapper): throw a more specific IOException that does not include InterruptedException Jul 9, 2019
@lestephane lestephane changed the title WebConnection(Wrapper): throw a more specific IOException that does not include InterruptedException WebConnection(Wrapper): throw a more specific IOException from close() that does not include InterruptedException Jul 9, 2019
@rbri

rbri commented Jul 11, 2019

Copy link
Copy Markdown
Member

Many thanks - merged

@rbri rbri closed this Jul 11, 2019
@rbri rbri reopened this Jul 11, 2019
@rbri
rbri merged commit e27c3ea into HtmlUnit:master Jul 11, 2019
@lestephane
lestephane deleted the autocloseable-warning branch July 15, 2019 13:11
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.

2 participants