diff options
author | Zipeng WU <zipeng.wu@sonarsource.com> | 2020-12-11 17:40:56 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2020-12-14 20:07:14 +0000 |
commit | ea1876bac569584125f2bd41f8c8fbf897cece2f (patch) | |
tree | 46f75a169de988e6ee98e911ad4df71ea5b4b134 /server/sonar-db-dao | |
parent | ffcea568c79640227b2fd9c562f642b9d087ea10 (diff) | |
download | sonarqube-ea1876bac569584125f2bd41f8c8fbf897cece2f.tar.gz sonarqube-ea1876bac569584125f2bd41f8c8fbf897cece2f.zip |
Close all resources automatically
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r-- | server/sonar-db-dao/src/main/java/org/sonar/db/notification/NotificationQueueDto.java | 17 |
1 files changed, 4 insertions, 13 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/notification/NotificationQueueDto.java b/server/sonar-db-dao/src/main/java/org/sonar/db/notification/NotificationQueueDto.java index c6a80800248..b7516aabdc0 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/notification/NotificationQueueDto.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/notification/NotificationQueueDto.java @@ -24,7 +24,6 @@ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; import org.sonar.api.notifications.Notification; @@ -72,18 +71,14 @@ public class NotificationQueueDto { } public static <T extends Notification> NotificationQueueDto toNotificationQueueDto(T notification) { - ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); - try { - ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream); + try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream)) { objectOutputStream.writeObject(notification); objectOutputStream.close(); return new NotificationQueueDto().setData(byteArrayOutputStream.toByteArray()); } catch (IOException e) { throw new SonarException("Unable to write notification", e); - - } finally { - IOUtils.closeQuietly(byteArrayOutputStream); } } @@ -92,15 +87,11 @@ public class NotificationQueueDto { return null; } - ByteArrayInputStream byteArrayInputStream = null; - try { - byteArrayInputStream = new ByteArrayInputStream(this.data); - ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream); + try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(this.data); + ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream)) { Object result = objectInputStream.readObject(); objectInputStream.close(); return (T) result; - } finally { - IOUtils.closeQuietly(byteArrayInputStream); } } |