-
Notifications
You must be signed in to change notification settings - Fork 68
Prefer try-with-resources for file error handling #17
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
Conversation
|
Maybe this is a good moment to update the Java requirements and use try-with-resources |
|
@gaul Try to rewrite this title and try to find where we are missing Java 7 features. We ASF developers are not so fast to update all 100 Maven projects, so it means we need some help from you contributors. |
| catch ( IOException e ) | ||
| { | ||
| throw new MojoExecutionException( e.getMessage(), e ); | ||
| getLog().warn( "Could not close " + PLUGIN_HELP_PATH + ": " + e.getMessage() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use a try-with-resources block, the exception will be eventually added as 'suppressed'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eolivelli
If @gaul would fix all Java 7 features then we should create a new Jira ticket as we did it in other projects.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to let maven plugins use error-prone with the fewest suppressions. Moving the entire project to Java 7 is one way to do this although I don't know if that aligns with the project's goals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It perfectly fits to our goals. ;-)
We set the Javac version 1.7 and we were updating the code to J7.
Later we will do the same for J8 - inner classes/Lambda, I/O, loops with method chaining, use of the class Optional, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Closing an InputStream in a finally block can mask exceptions thrown in the try or catch blocks. Found via error-prone. Reference: https://errorprone.info/bugpattern/Finally
|
Superseded by #18. |
Closing an
InputStreamin a finally block can mask exceptions thrownin the
tryorcatchblocks. Found via error-prone. Reference:https://errorprone.info/bugpattern/Finally