(tomcat) branch 9.0.x updated: Revert FileURLConnection changes - it does open an InputStream

[email protected]
Newsgroups gmane.comp.jakarta.tomcat.devel
Message-ID <178333701112.434004.15318630646006236810@gitbox3-he-fi.apache.org>
This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 0bb7a4cb7e Revert FileURLConnection changes - it does open an InputStream
0bb7a4cb7e is described below

commit 0bb7a4cb7ecb1376cb9eea36c9c9e14de3043c52
Author: Mark Thomas <[email protected]>
AuthorDate: Mon Jul 6 12:21:01 2026 +0100

    Revert FileURLConnection changes - it does open an InputStream
---
 java/org/apache/tomcat/util/buf/CloseableURLConnection.java | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/java/org/apache/tomcat/util/buf/CloseableURLConnection.java b/java/org/apache/tomcat/util/buf/CloseableURLConnection.java
index cf3510f8ca..f0faf5bf5e 100644
--- a/java/org/apache/tomcat/util/buf/CloseableURLConnection.java
+++ b/java/org/apache/tomcat/util/buf/CloseableURLConnection.java
@@ -146,15 +146,12 @@ public final class CloseableURLConnection extends URLConnection implements AutoC
             } catch (Throwable t) {
                 ExceptionUtils.handleThrowable(t);
             }
-        } else if (connection.getClass().getName().equals("sun.net.www.protocol.file.FileURLConnection")) {
+        } else if (!(connection instanceof HttpURLConnection)) {
             /*
-             * Internal JDK class so have to check by default name. If a JDK uses another name it will be handled by the
-             * final block.
+             * sun.net.www.protocol.file.FileURLConnection is known to open an InputStream for files.
              *
-             * NO-OP - known not to open a stream to read metadata
+             * Other cases could have used a stream as a side effect, possibly causing file locking.
              */
-        } else if (!(connection instanceof HttpURLConnection)) {
-            // Other cases could have used a stream as a side effect, possibly causing file locking.
             try (@SuppressWarnings("unused") InputStream is = connection.getInputStream()) {
                 // Explicitly close the InputStream to release its native resources.
             } catch (Throwable t) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.