fix for windows: refactored loadproperties function #128
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What problem does it solve?
Function load properties in utils.kt is used to read .properties files and acquire values from there into Properties object. The current implementation opens file stream, get the data from it but does not manually close it.
This is completely not a problem in Unix-like operation systems (Linux, MacOS), however Windows uses approach with blocking file handles, which means that while the process that requested an access to the file hadn't close the handle manually, no other process can perform any modifying operations with the file. And since Mirakle plugin is used by the gradle daemon that runs in background, file got blocked and the only way to get access to it again is to manually kill the gradle daemon process. In case you would like to delete some previously opened properties file or write something to it you will constantly receive an exception, and even commands like "del /f file" that are used to force-delete files will be able to do anything with it.
The current implementation, again, does not face any of these problems because it does not write anything to properties files multiple times, however I've got a fork of Mirakle that relies on properties files and sometimes needs to delete or create a new one, check if any of previous ones exist and delete them in this case. And also it is just a more decent approach to work with files - releasing the stream objects after the work is done with them.
Solution
The fix that I provided in this pull request does its job and properties files will now work properly in any OS including Windows. I know it looks ugly as a smoking pile, with all this try-try-try-check-if-null approach from good old Java 6 times, but it is actually the only solution that worked in my test environment (I tested it on Windows 10). For some reason when I tried to simplify the code in Kotlin it still wasn't able to close the file handle on Windows, so I did it the boomer-way