(
jni_env: *mut JNIEnv,
class_name: &str,
inv_args: &[InvocationArg],
)
| 637 | } |
| 638 | |
| 639 | fn do_create_java_list( |
| 640 | jni_env: *mut JNIEnv, |
| 641 | class_name: &str, |
| 642 | inv_args: &[InvocationArg], |
| 643 | ) -> errors::Result<Instance> { |
| 644 | debug(&format!( |
| 645 | "Creating a java list of class {} with {} elements", |
| 646 | class_name, |
| 647 | inv_args.len() |
| 648 | )); |
| 649 | unsafe { |
| 650 | // Factory invocation - first argument: create a jstring to pass as argument for the class_name |
| 651 | let class_name_jstring: jstring = |
| 652 | jni_utils::global_jobject_from_str(class_name, jni_env)?; |
| 653 | |
| 654 | // Factory invocation - rest of the arguments: Create a new object list of class InvocationArg |
| 655 | let size = inv_args.len() as i32; |
| 656 | let array_ptr = { |
| 657 | let j = (opt_to_res(cache::get_jni_new_object_array())?)( |
| 658 | jni_env, |
| 659 | size, |
| 660 | cache::get_invocation_arg_class()?, |
| 661 | ptr::null_mut(), |
| 662 | ); |
| 663 | jni_utils::create_global_ref_from_local_ref(j, jni_env)? |
| 664 | }; |
| 665 | let mut inv_arg_jobjects: Vec<jobject> = Vec::with_capacity(size as usize); |
| 666 | |
| 667 | // Factory invocation - rest of the arguments: populate the array |
| 668 | for i in 0..size { |
| 669 | // Create an InvocationArg Java Object |
| 670 | let inv_arg_java = inv_args[i as usize].as_java_ptr_with_global_ref(jni_env)?; |
| 671 | // Set it in the array |
| 672 | (opt_to_res(cache::get_jni_set_object_array_element())?)( |
| 673 | jni_env, |
| 674 | array_ptr, |
| 675 | i, |
| 676 | inv_arg_java, |
| 677 | ); |
| 678 | inv_arg_jobjects.push(inv_arg_java); |
| 679 | } |
| 680 | // Call the method of the factory that instantiates a new Java Array of `class_name`. |
| 681 | // This returns a Instance that acts like a proxy to the Java world. |
| 682 | let java_instance = (opt_to_res(cache::get_jni_call_static_object_method())?)( |
| 683 | jni_env, |
| 684 | cache::get_factory_class()?, |
| 685 | cache::get_factory_create_java_list_method()?, |
| 686 | class_name_jstring, |
| 687 | array_ptr, |
| 688 | ); |
| 689 | |
| 690 | // Check for exceptions before creating the globalref |
| 691 | Self::do_return(jni_env, ())?; |
| 692 | |
| 693 | let java_instance_global_instance = |
| 694 | jni_utils::create_global_ref_from_local_ref(java_instance, jni_env)?; |
| 695 | // Prevent memory leaks from the created local references |
| 696 | for inv_arg_jobject in inv_arg_jobjects { |
nothing calls this directly
no test coverage detected