This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 9e97bbe83d Correct use of try/finally
9e97bbe83d is described below
commit 9e97bbe83dd2e097adde418bd00d170ad689b775
Author: Mark Thomas <[email protected]>
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 bc183e09d6..1369acd2d9 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: [email protected]
For additional commands, e-mail: [email protected]