-
Notifications
You must be signed in to change notification settings - Fork 263
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
IOUtils.closeQuietly is deprecated and should be replaced with try-with-resource #1215
Comments
On the same topic, the PackedFile could declare to implement the Autoclosable interface, and be used in the same way. |
Please assign this to me as I am going to do some clean-up work on this during the week. |
There are 45 |
- removes the last use of copyWithClose - also, replaces yet another try/finally with try-with-resources Refers to RPTools#1215
- removes the last use of copyWithClose - also, replaces yet another try/finally with try-with-resources Refers to RPTools#1215
@emmebi I noticed that saved token files aren't getting their preview images in the Resource Library with the current dev code. |
@Phergus Can you detail this a little more? I will look into it in the week-end. |
I wonder if this could be related to #1266 instead |
( Drawing Foreground/Background Texture Select Using Resource Library Directory ) |
Maybe. It showed up very recently and I haven't had a chance to look at it more. The image is there. If I drop one of them on a map, the image shows up. Could also be #1268 |
Ok, apparently this was introduced with this patch. I checked out the develop branch, and if you go to the "Fix input PROPS type not working", images are shown. If you move three commit forwards, this doesn't work :( So, looking into this to understand why (I so much want to add tests ;) ) |
Found! The problem was indeed introduced in the getFileAsInputStream, which uses again a try with resources; but in this case the return value should be the InputStream, and the InputStream should not be closed at the exit of the function. Posting a PR for this soon. |
getFileAsInputStream was using a try with resources, so it was always returning a closed InputStream. Also, added a couple of unit tests as a starting point for properly testing this class. Refers to RPTools#1215
Fix tested and working. No other issues found. |
Is your feature request related to a problem? Please describe.
IOUtils.closeQuietly has been deprecated and is marked as such in the code. The alternative is to use try-with-resources statement, which will remove some repetitive code.
The reference documentation is here: https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html
Describe the solution you'd like
Remove all the try/finally blocks of code including IOUtils.closeQuietly with try-with-resource statement
Describe alternatives you've considered
I am not aware of alternative ways to accomplish this.
Additional context
I am looking at blocks of code like this:
which can now be rewritten as:
The same pattern could be applied also to other places, like for example PersistenceUtils.saveCampaignProperties
The text was updated successfully, but these errors were encountered: