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

compiler warnings: some AutoClosable class could throw InterruptedException #322

Closed
cburroughs opened this issue Aug 28, 2017 · 5 comments
Closed

Comments

@cburroughs
Copy link
Contributor

[WARNING] /home/jcsb/src/manta/java-manta/java-manta-client/src/main/java/com/joyent/manta/http/StandardHttpHelper.java:[57,8] auto-closeable resource com.joyent.manta.http.StandardHttpHelper has a member method close() that could throw InterruptedException
[WARNING] /home/jcsb/src/manta/java-manta/java-manta-client/src/main/java/com/joyent/manta/http/EncryptionHttpHelper.java:[77,8] auto-closeable resource com.joyent.manta.http.EncryptionHttpHelper has a member method close() that could throw InterruptedException
[WARNING] /home/jcsb/src/manta/java-manta/java-manta-client/src/main/java/com/joyent/manta/http/HttpHelper.java:[42,8] auto-closeable resource com.joyent.manta.http.HttpHelper has a member method close() that could throw InterruptedException
[WARNING] /home/jcsb/src/manta/java-manta/java-manta-client/src/main/java/com/joyent/manta/http/MantaConnectionContext.java:[19,8] auto-closeable resource com.joyent.manta.http.MantaConnectionContext has a member method close() that could throw InterruptedException

From https://docs.oracle.com/javase/8/docs/api/java/lang/AutoCloseable.html

Implementers of this interface are also strongly advised to not have the close method throw InterruptedException

@dekobon
Copy link
Contributor

dekobon commented Aug 29, 2017

I've been insofar unable to remove that warning with the approaches that I've tried. I would love for someone else to take a crack at it.

@cburroughs
Copy link
Contributor Author

As described oh so tersely at https://bugs.openjdk.java.net/browse/JDK-8155591, this warning isn't very precise. We are hitting it because void close() throws Exception means that InterruptedException (a child of Exception) "could" be thrown... which is the signature of AutoCloseable. It appears that the expectation is that anything implementing or subinterfacing AutoCloseable would explicitly list something more specific than Exception. I couldn't get SurpressWarnings to cover this up (it appears the set of things you can suppress is not the same as the set of all warnings).

Options:

  • (A) Fiddle with a bunch of method signatures to make this go away. I think that would always look confusing, not fix any real bugs, and involve changing public signatures.
  • (B) Compile with -Xlint:all,-try, which I think will keep all warnings except the "try" ones. I'm unsure what other warnings that includes https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javac.html#BHCJCABJ
  • (C) Do nothing and have routinely ignored warnings scrolling by during compilation.

None of those are great, (B) might be the least bad?

@dekobon
Copy link
Contributor

dekobon commented Aug 31, 2017

Aren't the typical "try" warnings useful? If so, I would lean towards (C). However, infuriating that may be.

@cburroughs
Copy link
Contributor Author

I'm not sure what all of the "try" warnings are, but yes I think the others are probably useful.

I suppose at the least we could add comments to relevant methods so that the next time someone tries to cleanup warnings they are saved some time.

@dekobon
Copy link
Contributor

dekobon commented Aug 31, 2017

👍

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

No branches or pull requests

2 participants