Skip to content

Commit 8c0af9e

Browse files
committed
Getting rid of invalid path exception at startup for Windows OS
1 parent 2d5016f commit 8c0af9e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/main/java/org/netbeans/modules/python/PythonUtility.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ public static List<Pair<String, String>> getPythonExes() throws IOException {
202202
? "where" : "which", python}, null).lines().forEach(exe -> {
203203
try {
204204
String striped = exe.strip();
205-
if (!striped.startsWith("INFO") && Files.isExecutable(Paths.get(striped))) {
205+
if (isValidFilePath(striped)) {
206206
String vers = getVersion(striped);
207207
if (!vers.isEmpty()) {
208208
versions.add(Pair.of(vers, striped));
@@ -218,6 +218,19 @@ public static List<Pair<String, String>> getPythonExes() throws IOException {
218218
return versions;
219219
}
220220

221+
private static boolean isValidFilePath(String filePath) {
222+
try {
223+
// Attempt to create a Path object from the provided string
224+
Path path = Paths.get(filePath);
225+
226+
// Check if the path is absolute and exists
227+
return path.isAbsolute() && path.toFile().exists() && Files.isExecutable(path);
228+
} catch (Exception e) {
229+
// An exception was thrown when parsing the path
230+
return false;
231+
}
232+
}
233+
221234
public static String[] getOsShell() {
222235
if (Utilities.isWindows()) {
223236
return new String[]{"cmd.exe", "/c"};

0 commit comments

Comments
 (0)