This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 11.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push: new 29690bbdb9 Correct use of try/finally 29690bbdb9 is described below commit 29690bbdb949c4bdb706279969236fb8dcd5c950 Author: Mark Thomas <ma...@apache.org> AuthorDate: Wed Aug 27 12:06:24 2025 +0100 Correct use of try/finally Ensure the correct finally blocks are run after any failure. --- java/org/apache/catalina/session/FileStore.java | 39 +++++++++++++------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/java/org/apache/catalina/session/FileStore.java b/java/org/apache/catalina/session/FileStore.java index 957b681ffa..3f552371ce 100644 --- a/java/org/apache/catalina/session/FileStore.java +++ b/java/org/apache/catalina/session/FileStore.java @@ -197,26 +197,29 @@ public final class FileStore extends StoreBase { } ClassLoader oldThreadContextCL = context.bind(null); - - Lock readLock = sessionLocksById.getLock(id).readLock(); - readLock.lock(); - try (FileInputStream fis = new FileInputStream(file.getAbsolutePath()); - ObjectInputStream ois = getObjectInputStream(fis)) { - if (!file.exists()) { - return null; - } - - StandardSession session = (StandardSession) manager.createEmptySession(); - session.readObjectData(ois); - session.setManager(manager); - return session; - } catch (FileNotFoundException e) { - if (contextLog.isDebugEnabled()) { - contextLog.debug(sm.getString("fileStore.noFile", id, file.getAbsolutePath()), e); + try { + Lock readLock = sessionLocksById.getLock(id).readLock(); + readLock.lock(); + try { + if (!file.exists()) { + return null; + } + try (FileInputStream fis = new FileInputStream(file.getAbsolutePath()); + ObjectInputStream ois = getObjectInputStream(fis)) { + StandardSession session = (StandardSession) manager.createEmptySession(); + session.readObjectData(ois); + session.setManager(manager); + return session; + } catch (FileNotFoundException e) { + if (contextLog.isDebugEnabled()) { + contextLog.debug(sm.getString("fileStore.noFile", id, file.getAbsolutePath()), e); + } + return null; + } + } finally { + readLock.unlock(); } - return null; } finally { - readLock.unlock(); context.unbind(oldThreadContextCL); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org