diff --git a/src/ffi/java/buffer.rs b/src/ffi/java/buffer.rs index 93225f5..4b6cbc2 100644 --- a/src/ffi/java/buffer.rs +++ b/src/ffi/java/buffer.rs @@ -147,8 +147,8 @@ pub extern "system" fn Java_mp_code_BufferController_send<'local>( self_ptr: jlong, input: JObject<'local>, ) { - let Ok(start) = env.get_field(&input, "start", "I") - .and_then(|sr| sr.i()) + let Ok(start) = env.get_field(&input, "start", "J") + .and_then(|sr| sr.j()) .jexcept(&mut env) .try_into() else { @@ -157,8 +157,8 @@ pub extern "system" fn Java_mp_code_BufferController_send<'local>( return; }; - let Ok(end) = env.get_field(&input, "end", "I") - .and_then(|er| er.i()) + let Ok(end) = env.get_field(&input, "end", "J") + .and_then(|er| er.j()) .jexcept(&mut env) .try_into() else { @@ -175,7 +175,7 @@ pub extern "system" fn Java_mp_code_BufferController_send<'local>( .map(|b| b.into()) .jexcept(&mut env); - let hash = env.get_field(&input, "hash", "Ljava/util/OptionalLong") + let hash = env.get_field(&input, "hash", "Ljava/util/OptionalLong;") .and_then(|hash| hash.l()) .and_then(|hash| { if env.call_method(&hash, "isPresent", "()Z", &[]).and_then(|r| r.z()).jexcept(&mut env) { diff --git a/src/ffi/java/mod.rs b/src/ffi/java/mod.rs index 50379bb..16bb9fa 100644 --- a/src/ffi/java/mod.rs +++ b/src/ffi/java/mod.rs @@ -110,8 +110,12 @@ impl JExceptable for Result where T: Default { fn jexcept(self, env: &mut jni::JNIEnv) -> T { if let Err(err) = &self { let msg = format!("{err}"); - env.throw_new("mp/code/exceptions/JNIException", msg) - .expect("A severe error occurred: we were unable to create a JNIException. This is an unrecoverable state."); + if let Err(err) = env.throw_new("mp/code/exceptions/JNIException", msg) { + if let Err(err) = env.exception_describe() { + tracing::error!("An exception occurred and we failed to even describe it: {err:#?}."); + } + panic!("A severe error occurred: we were unable to create a JNIException from {err:#?}. This is an unrecoverable state."); + } } self.unwrap_or_default() } @@ -121,8 +125,12 @@ impl JExceptable for Result where T: Default { fn jexcept(self, env: &mut jni::JNIEnv) -> T { if let Err(err) = &self { let msg = format!("{err}"); - env.throw_new("java/lang/IllegalArgumentException", msg) - .expect("A severe error occurred: we were unable to create a JNIException. This is an unrecoverable state."); + if let Err(err) = env.throw_new("java/lang/IllegalArgumentException", msg) { + if let Err(err) = env.exception_describe() { + tracing::error!("An exception occurred and we failed to even describe it: {err:#?}."); + } + panic!("A severe error occurred: we were unable to create a JNIException from {err:#?}. This is an unrecoverable state."); + } } self.unwrap_or_default() } diff --git a/src/ffi/java/workspace.rs b/src/ffi/java/workspace.rs index 504a4fa..9298e08 100644 --- a/src/ffi/java/workspace.rs +++ b/src/ffi/java/workspace.rs @@ -33,6 +33,10 @@ pub extern "system" fn Java_mp_code_Workspace_get_1buffer<'local>( self_ptr: jlong, input: JString<'local> ) -> jobject { + if input.is_null() { + return std::ptr::null_mut(); + } + let workspace = unsafe { Box::leak(Box::from_raw(self_ptr as *mut Workspace)) }; let path = unsafe { env.get_string_unchecked(&input) } .map(|path| path.to_string_lossy().to_string())