Skip to content

Commit

Permalink
JNI fixes:
Browse files Browse the repository at this point in the history
- Throw(NULL) should not clear pending exception.
- ThrowNew(..., NULL) should use default constructor.
  • Loading branch information
jfrijters committed Oct 25, 2013
1 parent b915417 commit 7330021
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions runtime/JniInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1726,15 +1726,18 @@ internal static jint Throw(JNIEnv* pEnv, jthrowable throwable)
{
ManagedJNIEnv env = pEnv->GetManagedJNIEnv();
Exception x = UnwrapRef(env, throwable) as Exception;
env.pendingException = x;
if (x != null)
{
env.pendingException = x;
}
return JNI_OK;
}

internal static jint ThrowNew(JNIEnv* pEnv, jclass clazz, byte* msg)
{
ManagedJNIEnv env = pEnv->GetManagedJNIEnv();
TypeWrapper wrapper = TypeWrapper.FromClass((java.lang.Class)UnwrapRef(env, clazz));
MethodWrapper mw = wrapper.GetMethodWrapper("<init>", "(Ljava.lang.String;)V", false);
MethodWrapper mw = wrapper.GetMethodWrapper("<init>", msg == null ? "()V" : "(Ljava.lang.String;)V", false);
if(mw != null)
{
jint rc;
Expand All @@ -1743,7 +1746,7 @@ internal static jint ThrowNew(JNIEnv* pEnv, jclass clazz, byte* msg)
{
wrapper.Finish();
java.lang.reflect.Constructor cons = (java.lang.reflect.Constructor)mw.ToMethodOrConstructor(false);
exception = (Exception)cons.newInstance(new object[] { StringFromOEM(msg) }, env.callerID);
exception = (Exception)cons.newInstance(msg == null ? new object[0] : new object[] { StringFromOEM(msg) }, env.callerID);
rc = JNI_OK;
}
catch(RetargetableJavaException x)
Expand Down

0 comments on commit 7330021

Please sign in to comment.