Skip to content

fix: drop useless import and clippy happy for java binding #5746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 12, 2025

Conversation

yihong0618
Copy link
Contributor

Which issue does this PR close?

Closes #5745

This patch do these things for java binding:

  • drop useless import
  • use latest stable api to the warning -> Replace once_cell::sync::OnceCell with the standard library's std::sync::OnceLock (available since Rust 1.70)
  • make clippy happy
  • add clippy ci for java binding

@github-actions github-actions bot added the releases-note/fix The PR fixes a bug or has a title that begins with "fix" label Mar 11, 2025
@tisonkun
Copy link
Member

In which PR we bump MSRV? I remember @Xuanwo suppose to hold on that the last time.

@yihong0618 yihong0618 changed the title fix: job useless import and clippy happy fix: drop useless import and clippy happy for java binding Mar 11, 2025
@@ -43,7 +43,9 @@ 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();
// Since OnceLock doesn't have a take() method, we can't remove the runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix it

@@ -43,7 +43,8 @@ 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();
// This is fine as the JVM is shutting down anyway
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, please don't change this unless we have good reasons.

Comment on lines 201 to 210
// It's okay if another thread initialized it first
let _ = RUNTIME.set(executor);

// Now RUNTIME should be initialized
Ok(RUNTIME.get().ok_or_else(|| {
opendal::Error::new(
opendal::ErrorKind::Unexpected,
"Failed to initialize default executor",
)
})
})?)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use get_or_init here to save an extra error check:

Ok(RUNTIME.get_or_init(|| executor))

@yihong0618
Copy link
Contributor Author

Ok(RUNTIME.get_or_init(|| executor))
I do not know GItHub pending in the comment
seems not quite simple to achieve, can you give some hint?
because make_tokio_executor also maybe fail and we need return OK

Comment on lines 198 to 205
// It's okay if another thread initialized it first
let _ = RUNTIME.set(executor);

// Now RUNTIME should be initialized
Ok(RUNTIME.get().ok_or_else(|| {
opendal::Error::new(
opendal::ErrorKind::Unexpected,
"Failed to initialize default executor",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// It's okay if another thread initialized it first
let _ = RUNTIME.set(executor);
// Now RUNTIME should be initialized
Ok(RUNTIME.get().ok_or_else(|| {
opendal::Error::new(
opendal::ErrorKind::Unexpected,
"Failed to initialize default executor",
Ok(RUNTIME.get_or_init(|| executor))

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if Rust corelib has a get_or_try_init. Or else we can add one ..

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signed-off-by: yihong0618 <[email protected]>
@yihong0618
Copy link
Contributor Author

is this way lose error message?

@Xuanwo
Copy link
Member

Xuanwo commented Mar 12, 2025

is this way lose error message?

Error handling happen at make_tokio_executor. The error case of RUNTIME.get().ok_or_else(|| xxx) will never happen.

Copy link
Member

@Xuanwo Xuanwo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great now, thank you @yihong0618

@Xuanwo Xuanwo merged commit bc19b76 into apache:main Mar 12, 2025
65 checks passed
@yihong0618
Copy link
Contributor Author

is this way lose error message?

Error handling happen at make_tokio_executor. The error case of RUNTIME.get().ok_or_else(|| xxx) will never happen.

learned thanks

@Xuanwo
Copy link
Member

Xuanwo commented Mar 12, 2025

Hi, @yihong0618 I just noticed that this PR removed the RUNTIME.take(), can you bring it back?

@yihong0618
Copy link
Contributor Author

Hi, @yihong0618 I just noticed that this PR removed the RUNTIME.take(), can you bring it back?

seems we can not use it here will take a look
IMO maybe its fine here

@Xuanwo
Copy link
Member

Xuanwo commented Mar 12, 2025

IMO maybe its fine here

Hi, I don't think it's fine. We know it works good before and I don't want to change here without good reasons.

@yihong0618
Copy link
Contributor Author

IMO maybe its fine here

Hi, I don't think it's fine. We know it works good before and I don't want to change here without good reasons.

yes you are right, will dig into it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
releases-note/fix The PR fixes a bug or has a title that begins with "fix"
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: follow all binding lint java part clippy for java
3 participants