This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new bc19b76a3 fix: drop useless import and clippy happy for java binding 
(#5746)
bc19b76a3 is described below

commit bc19b76a3e1fb99c84a7f310acd09e119618912b
Author: yihong <[email protected]>
AuthorDate: Wed Mar 12 12:34:13 2025 +0800

    fix: drop useless import and clippy happy for java binding (#5746)
    
    * fix: job useless import and clippy happy
    
    Signed-off-by: yihong0618 <[email protected]>
    
    * ci: make java binding working dir right
    
    Signed-off-by: yihong0618 <[email protected]>
    
    * fix: drop useless comments
    
    Signed-off-by: yihong0618 <[email protected]>
    
    * fix: use OpenDAL error instead of except
    
    Signed-off-by: yihong0618 <[email protected]>
    
    * fix: forget to lint
    
    Signed-off-by: yihong0618 <[email protected]>
    
    * fix: delete useless message
    
    Signed-off-by: yihong0618 <[email protected]>
    
    * fix: address comment
    
    Signed-off-by: yihong0618 <[email protected]>
    
    ---------
    
    Signed-off-by: yihong0618 <[email protected]>
---
 .github/workflows/ci_bindings_java.yml |  4 ++++
 bindings/java/src/async_operator.rs    |  4 +---
 bindings/java/src/convert.rs           |  8 ++++----
 bindings/java/src/executor.rs          | 26 +++++++++++++++-----------
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/.github/workflows/ci_bindings_java.yml 
b/.github/workflows/ci_bindings_java.yml
index a7f9397cd..954365750 100644
--- a/.github/workflows/ci_bindings_java.yml
+++ b/.github/workflows/ci_bindings_java.yml
@@ -57,6 +57,10 @@ jobs:
         run: |
           ./mvnw clean compile spotless:check
 
+      - name: Check Clippy
+        working-directory: bindings/java
+        run: cargo clippy -- -D warnings
+
   test:
     runs-on: ${{ matrix.os }}
     strategy:
diff --git a/bindings/java/src/async_operator.rs 
b/bindings/java/src/async_operator.rs
index 5f4721742..15a260d5e 100644
--- a/bindings/java/src/async_operator.rs
+++ b/bindings/java/src/async_operator.rs
@@ -15,7 +15,6 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use std::future::Future;
 use std::str::FromStr;
 use std::time::Duration;
 
@@ -30,10 +29,9 @@ use jni::sys::jobject;
 use jni::sys::jsize;
 use jni::JNIEnv;
 use opendal::layers::BlockingLayer;
-use opendal::operator_futures::FutureWrite;
 use opendal::raw::PresignedRequest;
+use opendal::Operator;
 use opendal::Scheme;
-use opendal::{Metadata, Operator};
 
 use crate::convert::jstring_to_string;
 use crate::convert::{
diff --git a/bindings/java/src/convert.rs b/bindings/java/src/convert.rs
index c0af00334..c5d04082e 100644
--- a/bindings/java/src/convert.rs
+++ b/bindings/java/src/convert.rs
@@ -69,8 +69,8 @@ pub(crate) fn string_to_jstring<'a>(
     )
 }
 
-pub(crate) fn get_optional_string_from_object<'a>(
-    env: &mut JNIEnv<'a>,
+pub(crate) fn get_optional_string_from_object(
+    env: &mut JNIEnv<'_>,
     obj: &JObject,
     method: &str,
 ) -> crate::Result<Option<String>> {
@@ -84,8 +84,8 @@ pub(crate) fn get_optional_string_from_object<'a>(
     }
 }
 
-pub(crate) fn get_optional_map_from_object<'a>(
-    env: &mut JNIEnv<'a>,
+pub(crate) fn get_optional_map_from_object(
+    env: &mut JNIEnv<'_>,
     obj: &JObject,
     method: &str,
 ) -> crate::Result<Option<HashMap<String, String>>> {
diff --git a/bindings/java/src/executor.rs b/bindings/java/src/executor.rs
index fd43bbd99..9ddedbd24 100644
--- a/bindings/java/src/executor.rs
+++ b/bindings/java/src/executor.rs
@@ -20,6 +20,7 @@ use std::ffi::c_void;
 use std::future::Future;
 use std::num::NonZeroUsize;
 use std::sync::atomic::{AtomicUsize, Ordering};
+use std::sync::OnceLock;
 use std::thread::available_parallelism;
 
 use jni::objects::JClass;
@@ -28,12 +29,11 @@ use jni::objects::JValue;
 use jni::sys::jlong;
 use jni::JNIEnv;
 use jni::JavaVM;
-use once_cell::sync::OnceCell;
 use tokio::task::JoinHandle;
 
 use crate::Result;
 
-static mut RUNTIME: OnceCell<Executor> = OnceCell::new();
+static RUNTIME: OnceLock<Executor> = OnceLock::new();
 thread_local! {
     static ENV: RefCell<Option<*mut jni::sys::JNIEnv>> = const { 
RefCell::new(None) };
 }
@@ -42,9 +42,7 @@ thread_local! {
 ///
 /// This function could be only called by java vm when unload this lib.
 #[no_mangle]
-pub unsafe extern "system" fn JNI_OnUnload(_: JavaVM, _: *mut c_void) {
-    let _ = RUNTIME.take();
-}
+pub unsafe extern "system" fn JNI_OnUnload(_: JavaVM, _: *mut c_void) {}
 
 /// # Safety
 ///
@@ -186,10 +184,16 @@ pub(crate) fn executor_or_default<'a>(
 ///
 /// This function could be only when the lib is loaded.
 unsafe fn default_executor<'a>(env: &mut JNIEnv<'a>) -> Result<&'a Executor> {
-    RUNTIME.get_or_try_init(|| {
-        make_tokio_executor(
-            env,
-            available_parallelism().map(NonZeroUsize::get).unwrap_or(1),
-        )
-    })
+    // Return the executor if it's already initialized
+    if let Some(runtime) = RUNTIME.get() {
+        return Ok(runtime);
+    }
+
+    // Try to initialize the executor
+    let executor = make_tokio_executor(
+        env,
+        available_parallelism().map(NonZeroUsize::get).unwrap_or(1),
+    )?;
+
+    Ok(RUNTIME.get_or_init(|| executor))
 }

Reply via email to