Skip to content

Commit a58dbd5

Browse files
committed
use get_optional
1 parent de8c915 commit a58dbd5

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

java/lance-jni/src/utils.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -76,28 +76,12 @@ pub fn extract_write_params(
7676
extract_storage_options(env, storage_options_obj)?;
7777

7878
// Extract storage options provider if present
79-
let storage_options_provider = if !storage_options_provider_obj.is_null() {
80-
// Check if it's an Optional.empty()
81-
let is_present = env
82-
.call_method(storage_options_provider_obj, "isPresent", "()Z", &[])?
83-
.z()?;
84-
if is_present {
85-
// Get the value from Optional
86-
let provider_obj = env
87-
.call_method(
88-
storage_options_provider_obj,
89-
"get",
90-
"()Ljava/lang/Object;",
91-
&[],
92-
)?
93-
.l()?;
94-
Some(JavaStorageOptionsProvider::new(env, provider_obj)?)
95-
} else {
96-
None
97-
}
98-
} else {
99-
None
100-
};
79+
let storage_options_provider = env.get_optional(storage_options_provider_obj, |env, obj| {
80+
let provider_obj = env
81+
.call_method(obj, "get", "()Ljava/lang/Object;", &[])?
82+
.l()?;
83+
JavaStorageOptionsProvider::new(env, provider_obj)
84+
})?;
10185

10286
let storage_options_provider_arc: Option<Arc<dyn StorageOptionsProvider>> =
10387
storage_options_provider.map(|v| Arc::new(v) as Arc<dyn StorageOptionsProvider>);

0 commit comments

Comments
 (0)