This is an automated email from the ASF dual-hosted git repository. markt 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 cb8f813515 Correct use of try/finally cb8f813515 is described below commit cb8f813515ff07519502f850738422d94c79be8b 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 e3747b4b66..591ad0a6e5 100644 --- a/java/org/apache/catalina/session/FileStore.java +++ b/java/org/apache/catalina/session/FileStore.java @@ -198,26 +198,29 @@ public final class FileStore extends StoreBase { } ClassLoader oldThreadContextCL = context.bind(Globals.IS_SECURITY_ENABLED, 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(Globals.IS_SECURITY_ENABLED, oldThreadContextCL); } } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org