This is an automated email from the ASF dual-hosted git repository. jamesnetherton pushed a commit to branch camel-4.14.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit b0acec7d26fd9a13c80dd09d036e8de2068f035a Author: James Netherton <[email protected]> AuthorDate: Tue Dec 23 14:21:57 2025 +0000 CAMEL-22784: Fix potential NPE in FileLockClusterView.tryLock --- .../apache/camel/component/file/cluster/FileLockClusterView.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/camel-file/src/main/java/org/apache/camel/component/file/cluster/FileLockClusterView.java b/components/camel-file/src/main/java/org/apache/camel/component/file/cluster/FileLockClusterView.java index 80896e1f1c32..c7b5971728a3 100644 --- a/components/camel-file/src/main/java/org/apache/camel/component/file/cluster/FileLockClusterView.java +++ b/components/camel-file/src/main/java/org/apache/camel/component/file/cluster/FileLockClusterView.java @@ -263,11 +263,13 @@ public class FileLockClusterView extends AbstractCamelClusterView { // Attempt to obtain cluster leadership LOGGER.debug("Try to acquire a lock on {} (cluster-member-id={})", leaderLockPath, localMember.getUuid()); - leaderLockFile = createRandomAccessFile(leaderLockPath); - leaderDataFile = createRandomAccessFile(leaderDataPath); lock = null; - lock = leaderLockFile.getChannel().tryLock(0, Math.max(1, leaderLockFile.getChannel().size()), false); + leaderLockFile = createRandomAccessFile(leaderLockPath); + leaderDataFile = createRandomAccessFile(leaderDataPath); + if (leaderLockFile != null && leaderDataFile != null) { + lock = leaderLockFile.getChannel().tryLock(0, Math.max(1, leaderLockFile.getChannel().size()), false); + } if (lockIsValid()) { LOGGER.info("Lock on file {} acquired (lock={}, cluster-member-id={})", leaderLockPath, lock,
