Author: rhuijben Date: Thu Aug 4 09:12:18 2011 New Revision: 1153799 URL: http://svn.apache.org/viewvc?rev=1153799&view=rev Log: Resolve a Java runtime exception when finalizing already disposed objects.
Found by: markphip (He reported the exception on [email protected]) Patch by: me * subversion/bindings/javahl/native/SVNBase.cpp (SVNBase::findCppAddrForJObject): Don't access the cpp object if it is already disposed. * subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java (testDispose): Add simple test. Modified: subversion/trunk/subversion/bindings/javahl/native/SVNBase.cpp subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java Modified: subversion/trunk/subversion/bindings/javahl/native/SVNBase.cpp URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/SVNBase.cpp?rev=1153799&r1=1153798&r2=1153799&view=diff ============================================================================== --- subversion/trunk/subversion/bindings/javahl/native/SVNBase.cpp (original) +++ subversion/trunk/subversion/bindings/javahl/native/SVNBase.cpp Thu Aug 4 09:12:18 2011 @@ -57,14 +57,17 @@ jlong SVNBase::findCppAddrForJObject(job if (JNIUtil::isJavaExceptionThrown()) return 0; - /* jthis is not guaranteed to be the same between JNI invocations, so - we do a little dance here and store the updated version in our - object for this invocation. - - findCppAddrForJObject() is, by necessity, called before any other - methods on the C++ object, so by doing this we can guarantee a valid - jthis pointer for subsequent uses. */ - (reinterpret_cast<SVNBase *> (cppAddr))->jthis = jthis; + if (cppAddr) + { + /* jthis is not guaranteed to be the same between JNI invocations, so + we do a little dance here and store the updated version in our + object for this invocation. + + findCppAddrForJObject() is, by necessity, called before any other + methods on the C++ object, so by doing this we can guarantee a + valid jthis pointer for subsequent uses. */ + (reinterpret_cast<SVNBase *> (cppAddr))->jthis = jthis; + } return cppAddr; } } Modified: subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java?rev=1153799&r1=1153798&r2=1153799&view=diff ============================================================================== --- subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java (original) +++ subversion/trunk/subversion/bindings/javahl/tests/org/apache/subversion/javahl/BasicTests.java Thu Aug 4 09:12:18 2011 @@ -81,6 +81,12 @@ public class BasicTests extends SVNTests } } + public void testDispose() throws Throwable + { + SVNClient cl = new SVNClient(); + cl.dispose(); + } + /** * Test LogDate(). * @throws Throwable @@ -3343,6 +3349,16 @@ public class BasicTests extends SVNTests } /** + * Test an explicit expose of SVNClient. + * (This used to cause a fatal exception in the Java Runtime) + */ + public void testDispose() throws Throwable + { + SVNClient cl = new SVNClient(); + cl.dispose(); + } + + /** * @return <code>file</code> converted into a -- possibly * <code>canonical</code>-ized -- Subversion-internal path * representation.
