mirror of
https://github.com/hexedtech/jni-toolbox.git
synced 2024-11-21 23:14:55 +01:00
fix: jni::errors::Error::NullPtr throws NullPtr
This commit is contained in:
parent
47bb45a387
commit
4d2debf789
3 changed files with 32 additions and 4 deletions
|
@ -106,7 +106,7 @@ impl ArgumentOptions {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// TODO should we panic here instead?
|
// 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;
|
return #ret_expr;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub(crate) fn generate_jni_wrapper(attrs: TokenStream, input: TokenStream) -> Re
|
||||||
Ok(fin) => fin,
|
Ok(fin) => fin,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// TODO should we panic instead?
|
// 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
|
#return_expr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
32
src/lib.rs
32
src/lib.rs
|
@ -14,12 +14,40 @@ pub trait JniToolboxError: std::error::Error {
|
||||||
|
|
||||||
impl JniToolboxError for jni::errors::Error {
|
impl JniToolboxError for jni::errors::Error {
|
||||||
fn jclass(&self) -> String {
|
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 {
|
impl JniToolboxError for jni::errors::JniError {
|
||||||
fn jclass(&self) -> String {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue