aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorZipeng WU <zipeng.wu@sonarsource.com>2020-12-11 17:40:56 +0100
committersonartech <sonartech@sonarsource.com>2020-12-14 20:07:14 +0000
commitea1876bac569584125f2bd41f8c8fbf897cece2f (patch)
tree46f75a169de988e6ee98e911ad4df71ea5b4b134 /server/sonar-db-dao
parentffcea568c79640227b2fd9c562f642b9d087ea10 (diff)
downloadsonarqube-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.java17
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);
}
}