Skip to content

Commit 7dc5372

Browse files
committed
JavaKit: check each classPath element exists before starting VM
Fixes #136.
1 parent 8e1d59b commit 7dc5372

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Sources/JavaKit/JavaKitVM/JavaVirtualMachine.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
#if canImport(FoundationEssentials)
16+
import FoundationEssentials
17+
#else
18+
import Foundation
19+
#endif
20+
1521
typealias JavaVMPointer = UnsafeMutablePointer<JavaVM?>
1622
#if canImport(Android)
1723
typealias JNIEnvPointer = UnsafeMutablePointer<JNIEnv?>
@@ -59,6 +65,12 @@ public final class JavaVirtualMachine: @unchecked Sendable {
5965
// Construct the complete list of VM options.
6066
var allVMOptions: [String] = []
6167
if !classPath.isEmpty {
68+
let fileManager = FileManager.default
69+
for path in classPath {
70+
if !fileManager.fileExists(atPath: path) {
71+
throw JavaKitError.classPathNotFound(path)
72+
}
73+
}
6274
let colonSeparatedClassPath = classPath.joined(separator: ":")
6375
allVMOptions.append("-Djava.class.path=\(colonSeparatedClassPath)")
6476
}
@@ -283,4 +295,8 @@ extension JavaVirtualMachine {
283295
}
284296
}
285297
}
298+
299+
enum JavaKitError: Error {
300+
case classPathNotFound(String)
301+
}
286302
}

0 commit comments

Comments
 (0)