mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-24 19:55:17 +01:00
Fixed JSONDatabaseHandler to avoid memory leak
Thanks Sonarcloud ^^
This commit is contained in:
parent
2dd8fcb13c
commit
493a525775
@ -99,15 +99,13 @@ public class JSONDatabaseHandler<T> extends AbstractJSONDatabaseHandler<T> {
|
|||||||
|
|
||||||
String toStore = getGson().toJson(instance);
|
String toStore = getGson().toJson(instance);
|
||||||
|
|
||||||
try {
|
try (FileWriter fileWriter = new FileWriter(file)) {
|
||||||
File tmpFile = new File(tableFolder, fileName + ".bak");
|
File tmpFile = new File(tableFolder, fileName + ".bak");
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
// Make a backup of file
|
// Make a backup of file
|
||||||
Files.copy(file.toPath(), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
Files.copy(file.toPath(), tmpFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||||
}
|
}
|
||||||
FileWriter fileWriter = new FileWriter(file);
|
|
||||||
fileWriter.write(toStore);
|
fileWriter.write(toStore);
|
||||||
fileWriter.close();
|
|
||||||
Files.deleteIfExists(tmpFile.toPath());
|
Files.deleteIfExists(tmpFile.toPath());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
plugin.logError("Could not save json file: " + path + " " + fileName + " " + e.getMessage());
|
plugin.logError("Could not save json file: " + path + " " + fileName + " " + e.getMessage());
|
||||||
|
Loading…
Reference in New Issue
Block a user