On Tue, Jun 30, 2026 at 9:18 PM <[email protected]> wrote:
>
> This is an automated email from the ASF dual-hosted git repository.
>
> markt-asf 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 2a3a07dff7 Fix another potential fd leak
> 2a3a07dff7 is described below
>
> commit 2a3a07dff73f399d39264b7247c2718e034efc7d
> Author: Mark Thomas <[email protected]>
> AuthorDate: Tue Jun 30 20:17:57 2026 +0100
>
>     Fix another potential fd leak
> ---
>  .../catalina/ssi/SSIServletExternalResolver.java   | 25 
> ++++++++++++++++++++--
>  1 file changed, 23 insertions(+), 2 deletions(-)
>
> diff --git a/java/org/apache/catalina/ssi/SSIServletExternalResolver.java 
> b/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
> index c39f338016..56ccefc9ce 100644
> --- a/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
> +++ b/java/org/apache/catalina/ssi/SSIServletExternalResolver.java
> @@ -36,6 +36,7 @@ import jakarta.servlet.http.HttpServletResponse;
>
>  import org.apache.catalina.connector.Connector;
>  import org.apache.catalina.connector.Request;
> +import org.apache.tomcat.util.ExceptionUtils;
>  import org.apache.tomcat.util.buf.B2CConverter;
>  import org.apache.tomcat.util.buf.UDecoder;
>  import org.apache.tomcat.util.http.Method;
> @@ -600,11 +601,21 @@ public class SSIServletExternalResolver implements 
> SSIExternalResolver {
>      @Override
>      public long getFileLastModified(String path, boolean virtual) throws 
> IOException {
>          long lastModified = 0;
> +        URLConnection urlConnection = null;
>          try {
> -            URLConnection urlConnection = getURLConnection(path, virtual);
> +            urlConnection = getURLConnection(path, virtual);
>              lastModified = urlConnection.getLastModified();
>          } catch (IOException ignore) {
>              // Ignore this. It will always fail for non-file based includes
> +        } finally {
> +            if (urlConnection != null) {
> +                try {
> +                    urlConnection.getInputStream().close();
> +                } catch (IOException ioe) {
> +                    ExceptionUtils.handleThrowable(ioe);
> +                    lastModified = 0;
> +                }
> +            }
>          }

So it should be possible to refactor it to:

    public long getFileLastModified(String path, boolean virtual)
throws IOException {
        long lastModified = 0;
        URLConnection urlConnection = null;
        try {
            urlConnection = getURLConnection(path, virtual);
            try (InputStream _ = urlConnection.getInputStream()) {
                lastModified = urlConnection.getLastModified();
            } catch (Exception e) {
                ExceptionUtils.handleThrowable(e);
            }
        } catch (IOException ignore) {
            // Ignore this. It will always fail for non-file based includes
        }
        return lastModified;
    }

Do your Claude actually like the code pattern we have in Tomcat right
now ? Somehow I doubt it.

Rémy

>          return lastModified;
>      }
> @@ -623,11 +634,21 @@ public class SSIServletExternalResolver implements 
> SSIExternalResolver {
>      @Override
>      public long getFileSize(String path, boolean virtual) throws IOException 
> {
>          long fileSize = -1;
> +        URLConnection urlConnection = null;
>          try {
> -            URLConnection urlConnection = getURLConnection(path, virtual);
> +            urlConnection = getURLConnection(path, virtual);
>              fileSize = urlConnection.getContentLengthLong();
>          } catch (IOException ignore) {
>              // Ignore this. It will always fail for non-file based includes
> +        } finally {
> +            if (urlConnection != null) {
> +                try {
> +                    urlConnection.getInputStream().close();
> +                } catch (IOException ioe) {
> +                    ExceptionUtils.handleThrowable(ioe);
> +                    fileSize = -1;
> +                }
> +            }
>          }
>          return fileSize;
>      }
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to