You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by bt...@apache.org on 2017/08/21 10:34:31 UTC
[5/5] james-project git commit: JAMES-2107 Run inspection profile
"Can rely on try with resources"
JAMES-2107 Run inspection profile "Can rely on try with resources"
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo
Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/49973add
Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/49973add
Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/49973add
Branch: refs/heads/master
Commit: 49973add09af64903f9da2936e582a56ad496f47
Parents: 4964e3d
Author: benwa <bt...@linagora.com>
Authored: Fri Aug 18 11:28:28 2017 +0700
Committer: benwa <bt...@linagora.com>
Committed: Mon Aug 21 17:33:55 2017 +0700
----------------------------------------------------------------------
.../mail/model/impl/SimpleMailboxMessageTest.java | 10 ++--------
.../transport/matchers/AttachmentFileNameIs.java | 7 ++-----
.../james/mailrepository/jcr/JCRMailRepository.java | 12 ++----------
.../file/FilePersistentObjectRepository.java | 16 +++++-----------
4 files changed, 11 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/james-project/blob/49973add/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
----------------------------------------------------------------------
diff --git a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
index 91e7c1a..86b6575 100644
--- a/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
+++ b/mailbox/store/src/test/java/org/apache/james/mailbox/store/mail/model/impl/SimpleMailboxMessageTest.java
@@ -78,23 +78,17 @@ public class SimpleMailboxMessageTest {
@Test
public void testInputStreamSize() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- try {
+ try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
byteArrayOutputStream.write(MESSAGE.getFullContent());
assertThat(byteArrayOutputStream.size()).isEqualTo(MESSAGE_CONTENT.getBytes(MESSAGE_CHARSET).length);
- } finally {
- byteArrayOutputStream.close();
}
}
@Test
public void testInputStreamSizeSpecialCharacters() throws IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- try {
+ try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
byteArrayOutputStream.write(MESSAGE_SPECIAL_CHAR.getFullContent());
assertThat(byteArrayOutputStream.size()).isEqualTo(MESSAGE_CONTENT_SPECIAL_CHAR.getBytes(MESSAGE_CHARSET).length);
- } finally {
- byteArrayOutputStream.close();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/49973add/mailet/standard/src/main/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java
----------------------------------------------------------------------
diff --git a/mailet/standard/src/main/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java b/mailet/standard/src/main/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java
index ea9ec07..b1f0f90 100755
--- a/mailet/standard/src/main/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java
+++ b/mailet/standard/src/main/java/org/apache/james/transport/matchers/AttachmentFileNameIs.java
@@ -244,9 +244,8 @@ public class AttachmentFileNameIs extends GenericMatcher {
*@param part
*/
protected boolean matchFoundInZip(Part part) throws MessagingException, IOException {
- ZipInputStream zis = new ZipInputStream(part.getInputStream());
-
- try {
+
+ try (ZipInputStream zis = new ZipInputStream(part.getInputStream())) {
while (true) {
ZipEntry zipEntry = zis.getNextEntry();
if (zipEntry == null) {
@@ -261,8 +260,6 @@ public class AttachmentFileNameIs extends GenericMatcher {
}
}
return false;
- } finally {
- zis.close();
}
}
http://git-wip-us.apache.org/repos/asf/james-project/blob/49973add/server/data/data-jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java b/server/data/data-jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java
index 8544473..475bc45 100644
--- a/server/data/data-jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java
+++ b/server/data/data-jcr/src/main/java/org/apache/james/mailrepository/jcr/JCRMailRepository.java
@@ -486,13 +486,9 @@ public class JCRMailRepository extends AbstractMailRepository implements MailRep
node = node.getProperty("jcr:content").getNode();
}
- @SuppressWarnings("deprecation")
- InputStream stream = node.getProperty("jcr:data").getStream();
- try {
+ try (@SuppressWarnings("deprecation") InputStream stream = node.getProperty("jcr:data").getStream()) {
Properties properties = System.getProperties();
return new MimeMessage(javax.mail.Session.getDefaultInstance(properties), stream);
- } finally {
- stream.close();
}
}
@@ -551,15 +547,11 @@ public class JCRMailRepository extends AbstractMailRepository implements MailRep
Property property = iterator.nextProperty();
String name = Text.unescapeIllegalJcrChars(property.getName().substring("jamesattr:".length()));
if (property.getType() == PropertyType.BINARY) {
- @SuppressWarnings("deprecation")
- InputStream input = property.getStream();
- try {
+ try (@SuppressWarnings("deprecation") InputStream input = property.getStream()) {
ObjectInputStream stream = new ObjectInputStream(input);
mail.setAttribute(name, (Serializable) stream.readObject());
} catch (ClassNotFoundException e) {
throw new IOException(e.getMessage());
- } finally {
- input.close();
}
} else {
mail.setAttribute(name, property.getString());
http://git-wip-us.apache.org/repos/asf/james-project/blob/49973add/server/data/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java
----------------------------------------------------------------------
diff --git a/server/data/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java b/server/data/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java
index 1fe1ba0..8397ac6 100644
--- a/server/data/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java
+++ b/server/data/data-library/src/main/java/org/apache/james/repository/file/FilePersistentObjectRepository.java
@@ -103,17 +103,11 @@ public class FilePersistentObjectRepository extends AbstractFileRepository imple
* java.lang.Object)
*/
public synchronized void put(String key, Object value) {
- try {
- final OutputStream outputStream = getOutputStream(key);
-
- try {
- final ObjectOutputStream stream = new ObjectOutputStream(outputStream);
- stream.writeObject(value);
- if (DEBUG)
- getLogger().debug("storing object " + value + " for key " + key);
- } finally {
- outputStream.close();
- }
+ try (OutputStream outputStream = getOutputStream(key)) {
+ final ObjectOutputStream stream = new ObjectOutputStream(outputStream);
+ stream.writeObject(value);
+ if (DEBUG)
+ getLogger().debug("storing object " + value + " for key " + key);
} catch (Exception e) {
throw new RuntimeException("Exception caught while storing an object: " + e);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org