Skip to content

Commit 1e79e87

Browse files
committed
fix(java): cursor callback cleanup
1 parent 3786fd2 commit 1e79e87

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

src/ffi/java/cursor.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ use crate::{
55
use jni::{Env, objects::JObject};
66
use jni_toolbox::jni;
77

8-
use super::null_check;
9-
108
/// Try to fetch a [Cursor], or returns null if there's nothing.
119
#[jni(package = "mp.code", class = "CursorController")]
1210
fn try_recv(controller: &mut crate::cursor::Controller) -> Result<Option<CursorEvent>, ControllerError> {
@@ -32,11 +30,14 @@ fn callback<'local>(
3230
controller: &mut crate::cursor::Controller,
3331
cb: JObject<'local>,
3432
) -> Result<(), jni::errors::Error> {
35-
null_check!(cb);
33+
if cb.is_null() {
34+
return Err(jni::errors::Error::NullPtr("cursor callback is null"));
35+
}
36+
3637
let cb_ref = env.new_global_ref(cb)?;
3738

3839
controller.callback(move |controller: crate::cursor::Controller| {
39-
let res = super::jvm().attach_current_thread(|mut env| {
40+
let res: Result<(), jni::errors::Error> = super::jvm().attach_current_thread(|env| {
4041
env.with_local_frame(5, |env| {
4142
use jni_toolbox::IntoJavaObject;
4243
let jcontroller = controller.into_java_object(env)?;
@@ -46,7 +47,7 @@ fn callback<'local>(
4647
jni::jni_sig!((arg1: java.lang.Object) -> ()),
4748
&[jni::objects::JValue::Object(&jcontroller)],
4849
)?;
49-
Ok(())
50+
Ok::<(), jni::errors::Error>(())
5051
})?;
5152

5253
Ok(())

0 commit comments

Comments
 (0)