@@ -61,12 +61,12 @@ struct JNIAsyncTests {
6161 """
6262 @_cdecl( " Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2 " )
6363 public func Java_com_example_swift_SwiftModule__00024asyncVoid__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, result_future: jobject?) {
64- let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
64+ nonisolated(unsafe) let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
6565 var task: Task<Void, Never>? = nil
6666 #if swift(>=6.2)
6767 if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *) {
6868 task = Task.immediate {
69- var environment = environment!
69+ var environment = try! JavaVirtualMachine.shared().environment()
7070 defer {
7171 let deferEnvironment = try! JavaVirtualMachine.shared().environment()
7272 deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture)
@@ -137,12 +137,12 @@ struct JNIAsyncTests {
137137 """
138138 @_cdecl( " Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2 " )
139139 public func Java_com_example_swift_SwiftModule__00024async__Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, result_future: jobject?) {
140- let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
140+ nonisolated(unsafe) let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
141141 var task: Task<Void, Never>? = nil
142142 #if swift(>=6.2)
143143 if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *) {
144144 task = Task.immediate {
145- var environment = environment!
145+ var environment = try! JavaVirtualMachine.shared().environment()
146146 defer {
147147 let deferEnvironment = try! JavaVirtualMachine.shared().environment()
148148 deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture)
@@ -227,12 +227,12 @@ struct JNIAsyncTests {
227227 """
228228 @_cdecl( " Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2 " )
229229 public func Java_com_example_swift_SwiftModule__00024async__JLjava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, i: jlong, result_future: jobject?) {
230- let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
230+ nonisolated(unsafe) let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
231231 var task: Task<Void, Never>? = nil
232232 #if swift(>=6.2)
233233 if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *) {
234234 task = Task.immediate {
235- var environment = environment!
235+ var environment = try! JavaVirtualMachine.shared().environment()
236236 defer {
237237 let deferEnvironment = try! JavaVirtualMachine.shared().environment()
238238 deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture)
@@ -320,12 +320,12 @@ struct JNIAsyncTests {
320320 guard let c$ else {
321321 fatalError( " c memory address was null in call to \\ (#function)! " )
322322 }
323- let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
323+ nonisolated(unsafe) let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
324324 var task: Task<Void, Never>? = nil
325325 #if swift(>=6.2)
326326 if #available(macOS 26.0, iOS 26.0, watchOS 26.0, tvOS 26.0, *) {
327327 task = Task.immediate {
328- var environment = environment!
328+ var environment = try! JavaVirtualMachine.shared().environment()
329329 defer {
330330 let deferEnvironment = try! JavaVirtualMachine.shared().environment()
331331 deferEnvironment.interface.DeleteGlobalRef(deferEnvironment, globalFuture)
@@ -403,8 +403,8 @@ struct JNIAsyncTests {
403403 """
404404 @_cdecl( " Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2 " )
405405 public func Java_com_example_swift_SwiftModule__00024async__Ljava_lang_String_2Ljava_util_concurrent_CompletableFuture_2(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, s: jstring?, result_future: jobject?) {
406- let s = environment.interface.NewGlobalRef(environment, s)
407- let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
406+ nonisolated(unsafe) let s = environment.interface.NewGlobalRef(environment, s)
407+ nonisolated(unsafe) let globalFuture = environment.interface.NewGlobalRef(environment, result_future)
408408 ...
409409 defer {
410410 let deferEnvironment = try! JavaVirtualMachine.shared().environment()
0 commit comments