From de71e6c3532a3db911a887d2c907a8dc2c1e3956 Mon Sep 17 00:00:00 2001 From: Philip Durbin Date: Tue, 5 Sep 2023 16:17:31 -0400 Subject: [PATCH] use try with resources in JsonUtil #9315 --- .../edu/harvard/iq/dataverse/util/json/JsonUtil.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/edu/harvard/iq/dataverse/util/json/JsonUtil.java b/src/main/java/edu/harvard/iq/dataverse/util/json/JsonUtil.java index 09d02854bab..cf8b64520de 100644 --- a/src/main/java/edu/harvard/iq/dataverse/util/json/JsonUtil.java +++ b/src/main/java/edu/harvard/iq/dataverse/util/json/JsonUtil.java @@ -11,6 +11,7 @@ import java.util.logging.Logger; import jakarta.json.Json; import jakarta.json.JsonArray; +import jakarta.json.JsonReader; import jakarta.json.JsonWriter; import jakarta.json.JsonWriterFactory; import jakarta.json.stream.JsonGenerator; @@ -60,13 +61,17 @@ public static String prettyPrint(jakarta.json.JsonObject jsonObject) { public static jakarta.json.JsonObject getJsonObject(String serializedJson) { try (StringReader rdr = new StringReader(serializedJson)) { - return Json.createReader(rdr).readObject(); + try (JsonReader jsonReader = Json.createReader(rdr)) { + return jsonReader.readObject(); + } } } public static jakarta.json.JsonArray getJsonArray(String serializedJson) { try (StringReader rdr = new StringReader(serializedJson)) { - return Json.createReader(rdr).readArray(); + try (JsonReader jsonReader = Json.createReader(rdr)) { + return jsonReader.readArray(); + } } } }