Skip to content

Commit 3436f46

Browse files
authored
Merge pull request #150 from PADL/lhoward/class-path-validate
2 parents cad41a5 + b08446a commit 3436f46

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

1723
public final class JavaVirtualMachine: @unchecked Sendable {
@@ -54,6 +60,12 @@ public final class JavaVirtualMachine: @unchecked Sendable {
5460
// Construct the complete list of VM options.
5561
var allVMOptions: [String] = []
5662
if !classPath.isEmpty {
63+
let fileManager = FileManager.default
64+
for path in classPath {
65+
if !fileManager.fileExists(atPath: path) {
66+
throw JavaKitError.classPathEntryNotFound(entry: path, classPath: classPath)
67+
}
68+
}
5769
let colonSeparatedClassPath = classPath.joined(separator: ":")
5870
allVMOptions.append("-Djava.class.path=\(colonSeparatedClassPath)")
5971
}
@@ -268,4 +280,8 @@ extension JavaVirtualMachine {
268280
}
269281
}
270282
}
283+
284+
enum JavaKitError: Error {
285+
case classPathEntryNotFound(entry: String, classPath: [String])
286+
}
271287
}

0 commit comments

Comments
 (0)