Modern Apps git

← Modern-Apps.git

networklocation: migrate deprecated JNI array helpers to typed arrays

Commit
50cc09183c24c8dab87083fd95a8cd4d12889124
Author
Vayun Mathur <[email protected]>
When
2026-12-01 22:04 UTC (4 days ago)
Parents
7061396
The two deprecated Env array calls in estimatePosition
(get_array_length, get_double_array_region) now use
JDoubleArray len/get_region from jni 0.22, matching the
set_region call already migrated in the same function.
A third, clippy-invisible call in jni_tests.rs behind
#[allow(deprecated)] is migrated the same way and the
allow removed, so no deprecated array helper remains
in the crate even where clippy did not count it.

In jni 0.22.4 the deprecated Env wrappers delegate to the
same TypeArraySealed region call and the same
GetArrayLength JNI call, so this is byte-for-byte identical:
same copy semantics (region, not get_elements/critical),
same null and IndexOutOfBounds error behaviour mapped to
null at the same call site. len() returns usize directly,
dropping the redundant as-cast.

Verified: cargo clippy --locked -p
network_location_position_estimation_rust --all-targets
shows no deprecated warnings (only the pre-existing
items-after-test-module note), cargo test -p
network_location_position_estimation_rust (67 passed,
including the JNI tests estimate_position_via_jni,
geocoder_via_jni and wps_store_null_handle_contract),
cargo fmt --check clean.

Diff

networklocation/src/main/rust/src/jni.rs
diff --git a/networklocation/src/main/rust/src/jni.rs b/networklocation/src/main/rust/src/jni.rsindex 92065397a0..acce619e43 100644--- a/networklocation/src/main/rust/src/jni.rs+++ b/networklocation/src/main/rust/src/jni.rs@@ -198,9 +198,9 @@ pub extern "system" fn Java_com_vayunmathur_networklocation_NetworkLocationNativ     beacons: JDoubleArray<'l>, ) -> jdoubleArray {     env.with_env(|env| -> jni::errors::Result<jdoubleArray> {-        let len = env.get_array_length(&beacons).unwrap_or(0) as usize;+        let len = beacons.len(env).unwrap_or(0);         let mut buf = vec![0f64; len];-        if env.get_double_array_region(&beacons, 0, &mut buf).is_err() {+        if beacons.get_region(env, 0, &mut buf).is_err() {             return Ok(std::ptr::null_mut());         } 
networklocation/src/main/rust/src/jni_tests.rs
diff --git a/networklocation/src/main/rust/src/jni_tests.rs b/networklocation/src/main/rust/src/jni_tests.rsindex 26ae8a3e12..518ac145f5 100644--- a/networklocation/src/main/rust/src/jni_tests.rs+++ b/networklocation/src/main/rust/src/jni_tests.rs@@ -193,8 +193,7 @@ fn estimate_position_via_jni() {         assert!(!raw.is_null());         let arr = unsafe { JDoubleArray::from_raw(&*env, raw) };         let mut buf = [0f64; 3];-        #[allow(deprecated)]-        env.get_double_array_region(&arr, 0, &mut buf).expect("region");+        arr.get_region(env, 0, &mut buf).expect("region");         assert!((buf[0] - 37.0).abs() < 0.01, "lat {}", buf[0]);         assert!((buf[1] + 122.0).abs() < 0.01, "lon {}", buf[1]);         assert!(buf[2] > 0.0, "accuracy {}", buf[2]);