This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit 5c3f7405285fb666e3fc8ff4d1d7c813502d2506
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Dec 14 10:18:29 2023 -0500

    Use try-with-resources
---
 .../java/org/apache/commons/mail/util/MimeMessageUtils.java | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java 
b/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
index 0626b4b..d773009 100644
--- a/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
+++ b/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
@@ -87,16 +87,9 @@ public final class MimeMessageUtils {
      * @throws IOException        creating the MimeMessage failed
      */
     public static MimeMessage createMimeMessage(final Session session, final 
String source) throws MessagingException, IOException {
-        ByteArrayInputStream is = null;
-
-        try {
-            final byte[] byteSource = 
source.getBytes(Charset.defaultCharset());
-            is = new SharedByteArrayInputStream(byteSource);
-            return createMimeMessage(session, is);
-        } finally {
-            if (is != null) {
-                is.close();
-            }
+        final byte[] byteSource = source.getBytes(Charset.defaultCharset());
+        try (ByteArrayInputStream inputStream = new 
SharedByteArrayInputStream(byteSource)) {
+            return createMimeMessage(session, inputStream);
         }
     }
 

Reply via email to