From 3d7b6b4ac7a53a43f4234a50e7d262668193596f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Sautter?= Date: Sat, 22 Jun 2024 15:36:14 +0200 Subject: [PATCH] [java] use Files.notExists to check files #14088 --- java/src/org/openqa/selenium/internal/Require.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/java/src/org/openqa/selenium/internal/Require.java b/java/src/org/openqa/selenium/internal/Require.java index 14ed1600004f7..476966a597bb4 100644 --- a/java/src/org/openqa/selenium/internal/Require.java +++ b/java/src/org/openqa/selenium/internal/Require.java @@ -442,7 +442,9 @@ public Path isFile() { if (path == null) { throw new IllegalStateException(String.format(MUST_BE_SET, name)); } - if (!Files.exists(path)) { + // notExists returns false in case it is impossible to determinate the exact result of a link + // target e.g. Windows app execution aliases + if (Files.notExists(path)) { throw new IllegalStateException(String.format(MUST_EXIST, name, path)); } if (!Files.isRegularFile(path)) { @@ -455,7 +457,9 @@ public Path isDirectory() { if (path == null) { throw new IllegalStateException(String.format(MUST_BE_SET, name)); } - if (!Files.exists(path)) { + // notExists returns false in case it is impossible to determinate the exact result of a link + // target e.g. Windows app execution aliases + if (Files.notExists(path)) { throw new IllegalStateException(String.format(MUST_EXIST, name, path)); } if (!Files.isDirectory(path)) { @@ -468,7 +472,9 @@ public Path isExecutable() { if (path == null) { throw new IllegalStateException(String.format(MUST_BE_SET, name)); } - if (!Files.exists(path)) { + // notExists returns false in case it is impossible to determinate the exact result of a link + // target e.g. Windows app execution aliases + if (Files.notExists(path)) { throw new IllegalStateException(String.format(MUST_EXIST, name, path)); } // do not check for isRegularFile here, there are executable none regular files e.g. Windows