fix: jni::errors::Error::NullPtr throws NullPtr

This commit is contained in:
əlemi 2024-09-24 05:02:23 +02:00
parent 47bb45a387
commit 4d2debf789
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 32 additions and 4 deletions

View file

@ -106,7 +106,7 @@ impl ArgumentOptions {
Ok(x) => x,
Err(e) => {
// TODO should we panic here instead?
let _ = #env.throw_new("java/lang/RuntimeException", format!("{e:?}"));
let _ = #env.throw_new(e.jclass(), format!("{e:?}"));
return #ret_expr;
},
};

View file

@ -92,7 +92,7 @@ pub(crate) fn generate_jni_wrapper(attrs: TokenStream, input: TokenStream) -> Re
Ok(fin) => fin,
Err(e) => {
// TODO should we panic instead?
let _ = #env_iden.throw_new("java/lang/RuntimeException", format!("{e:?}"));
let _ = #env_iden.throw_new(e.jclass(), format!("{e:?}"));
#return_expr
}
}

View file

@ -14,12 +14,40 @@ pub trait JniToolboxError: std::error::Error {
impl JniToolboxError for jni::errors::Error {
fn jclass(&self) -> String {
"java/lang/RuntimeException".to_string()
match self {
jni::errors::Error::NullPtr(_) => "java/lang/NullPointerException",
_ => "java/lang/RuntimeException",
// jni::errors::Error::WrongJValueType(_, _) => todo!(),
// jni::errors::Error::InvalidCtorReturn => todo!(),
// jni::errors::Error::InvalidArgList(_) => todo!(),
// jni::errors::Error::MethodNotFound { name, sig } => todo!(),
// jni::errors::Error::FieldNotFound { name, sig } => todo!(),
// jni::errors::Error::JavaException => todo!(),
// jni::errors::Error::JNIEnvMethodNotFound(_) => todo!(),
// jni::errors::Error::NullDeref(_) => todo!(),
// jni::errors::Error::TryLock => todo!(),
// jni::errors::Error::JavaVMMethodNotFound(_) => todo!(),
// jni::errors::Error::FieldAlreadySet(_) => todo!(),
// jni::errors::Error::ThrowFailed(_) => todo!(),
// jni::errors::Error::ParseFailed(_, _) => todo!(),
// jni::errors::Error::JniCall(_) => todo!(),
}
.to_string()
}
}
impl JniToolboxError for jni::errors::JniError {
fn jclass(&self) -> String {
"java/lang/RuntimeException".to_string()
match self {
_ => "java/lang/RuntimeException",
// jni::errors::JniError::Unknown => todo!(),
// jni::errors::JniError::ThreadDetached => todo!(),
// jni::errors::JniError::WrongVersion => todo!(),
// jni::errors::JniError::NoMemory => todo!(),
// jni::errors::JniError::AlreadyCreated => todo!(),
// jni::errors::JniError::InvalidArguments => todo!(),
// jni::errors::JniError::Other(_) => todo!(),
}
.to_string()
}
}