You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by am...@apache.org on 2020/10/15 10:13:54 UTC
svn commit: r1882519 - in
/subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native:
JNIUtil.cpp JNIUtil.h
Author: amiloslavskiy
Date: Thu Oct 15 10:13:54 2020
New Revision: 1882519
URL: http://svn.apache.org/viewvc?rev=1882519&view=rev
Log:
JavaHL: Introduce new helper class to temporarily stash Java exceptions
This will be used in subsequent commits. Committed separately to
facilitate code review and cherry-picks.
[in subversion/bindings/javahl]
* native/JNIUtil.cpp
* native/JNIUtil.h
New class 'StashException', please refer to code comments.
Modified:
subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp
subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.h
Modified: subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp?rev=1882519&r1=1882518&r2=1882519&view=diff
==============================================================================
--- subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp (original)
+++ subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.cpp Thu Oct 15 10:13:54 2020
@@ -1169,3 +1169,28 @@ jthrowable JNIUtil::unwrapJavaException(
return
WrappedException::get_exception(err->pool);
}
+
+StashException::StashException(JNIEnv* env)
+{
+ m_env = env;
+ m_stashed = NULL;
+ stashException();
+}
+
+StashException::~StashException()
+{
+ if (m_stashed)
+ m_env->Throw(m_stashed);
+}
+
+void StashException::stashException()
+{
+ jthrowable jexc = m_env->ExceptionOccurred();
+ if (!jexc)
+ return;
+
+ if (!m_stashed)
+ m_stashed = jexc;
+
+ m_env->ExceptionClear();
+}
Modified: subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.h
URL: http://svn.apache.org/viewvc/subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.h?rev=1882519&r1=1882518&r2=1882519&view=diff
==============================================================================
--- subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.h (original)
+++ subversion/branches/javahl-1.14-fixes/subversion/bindings/javahl/native/JNIUtil.h Thu Oct 15 10:13:54 2020
@@ -330,4 +330,37 @@ class JNIUtil
} \
} while(0)
+/**
+ * If there's an exception pending, temporarily stash it away, then
+ * re-throw again in destructor. The goal is to allow some Java calls
+ * to be made despite a pending exception. For example, doing some
+ * necessary cleanup.
+ */
+class StashException
+{
+ public:
+ /*
+ * Works like stashException().
+ */
+ StashException(JNIEnv* env);
+
+ /**
+ * If there's an exception stashed, re-throws it.
+ */
+ ~StashException();
+
+ /**
+ * Check for a pending exception.
+ * If present, stash it away until this class's destructor.
+ * If another exception is already stashed, forget the _new_ one. The
+ * reason behind it is that usually the first exception is the most
+ * informative.
+ */
+ void stashException();
+
+ private:
+ JNIEnv* m_env;
+ jthrowable m_stashed;
+};
+
#endif // JNIUTIL_H