This is an automated email from the ASF dual-hosted git repository. lihan pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push: new 03ae0436fa Replace manually invoke close method with try-with-resources. (#590) 03ae0436fa is described below commit 03ae0436fa1ffefe334432238b020532a7165016 Author: Andrei Briukhov <andreybr...@gmail.com> AuthorDate: Fri Feb 10 12:16:41 2023 +0300 Replace manually invoke close method with try-with-resources. (#590) --- .../coyote/http11/filters/ChunkedOutputFilter.java | 30 ++++++++++++---------- .../xreflection/ReflectionLessCodeGenerator.java | 8 +++--- .../apache/catalina/core/TestAsyncContextImpl.java | 13 +++------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java index 6eedd81eea..c7a6f27a48 100644 --- a/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java +++ b/java/org/apache/coyote/http11/filters/ChunkedOutputFilter.java @@ -177,20 +177,22 @@ public class ChunkedOutputFilter implements OutputFilter { lastChunk.position(0).limit(lastChunk.capacity()); ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - OutputStreamWriter osw = new OutputStreamWriter(baos, StandardCharsets.ISO_8859_1); - for (Map.Entry<String,String> trailerField : trailerFields.entrySet()) { - // Ignore disallowed headers - if (disallowedTrailerFieldNames.contains( - trailerField.getKey().toLowerCase(Locale.ENGLISH))) { - continue; - } - osw.write(trailerField.getKey()); - osw.write(':'); - osw.write(' '); - osw.write(trailerField.getValue()); - osw.write("\r\n"); - } - osw.close(); + + try (OutputStreamWriter osw = new OutputStreamWriter(baos, StandardCharsets.ISO_8859_1)) { + for (Map.Entry<String, String> trailerField : trailerFields.entrySet()) { + // Ignore disallowed headers + if (disallowedTrailerFieldNames.contains( + trailerField.getKey().toLowerCase(Locale.ENGLISH))) { + continue; + } + osw.write(trailerField.getKey()); + osw.write(':'); + osw.write(' '); + osw.write(trailerField.getValue()); + osw.write("\r\n"); + } + } + buffer.doWrite(ByteBuffer.wrap(baos.toByteArray())); buffer.doWrite(crlfChunk); diff --git a/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java b/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java index a06d78dce5..d79983e4f9 100644 --- a/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java +++ b/java/org/apache/tomcat/util/xreflection/ReflectionLessCodeGenerator.java @@ -185,10 +185,10 @@ final class ReflectionLessCodeGenerator { .append(System.lineSeparator()); //end - class File destination = new File(directory, className+".java"); - BufferedWriter writer = new BufferedWriter(new FileWriter(destination, false)); - writer.write(code.toString()); - writer.flush(); - writer.close(); + try (BufferedWriter writer = new BufferedWriter(new FileWriter(destination, false))) { + writer.write(code.toString()); + writer.flush(); + } } diff --git a/test/org/apache/catalina/core/TestAsyncContextImpl.java b/test/org/apache/catalina/core/TestAsyncContextImpl.java index 14621803ed..fc755166b2 100644 --- a/test/org/apache/catalina/core/TestAsyncContextImpl.java +++ b/test/org/apache/catalina/core/TestAsyncContextImpl.java @@ -1521,15 +1521,10 @@ public class TestAsyncContextImpl extends TomcatBaseTest { // Just for debugging async.setTimeout(100000); - ExecutorService executor = Executors.newSingleThreadExecutor(); - executor.submit(new Runnable() { - - @Override - public void run() { - async.dispatch("/ServletC"); - } - }); - executor.shutdown(); + try (ExecutorService executor = Executors.newSingleThreadExecutor()) { + executor.submit(() -> async.dispatch("/ServletC")); + executor.shutdown(); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org