Skip to content

Commit

Permalink
JavaKit: check each classPath element exists before starting VM
Browse files Browse the repository at this point in the history
  • Loading branch information
lhoward committed Nov 5, 2024
1 parent cad41a5 commit b08446a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Sources/JavaKit/JavaKitVM/JavaVirtualMachine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
//
//===----------------------------------------------------------------------===//

#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif

typealias JavaVMPointer = UnsafeMutablePointer<JavaVM?>

public final class JavaVirtualMachine: @unchecked Sendable {
Expand Down Expand Up @@ -54,6 +60,12 @@ public final class JavaVirtualMachine: @unchecked Sendable {
// Construct the complete list of VM options.
var allVMOptions: [String] = []
if !classPath.isEmpty {
let fileManager = FileManager.default
for path in classPath {
if !fileManager.fileExists(atPath: path) {
throw JavaKitError.classPathEntryNotFound(entry: path, classPath: classPath)
}
}
let colonSeparatedClassPath = classPath.joined(separator: ":")
allVMOptions.append("-Djava.class.path=\(colonSeparatedClassPath)")
}
Expand Down Expand Up @@ -268,4 +280,8 @@ extension JavaVirtualMachine {
}
}
}

enum JavaKitError: Error {
case classPathEntryNotFound(entry: String, classPath: [String])
}
}

0 comments on commit b08446a

Please sign in to comment.