From 8f5590cb9fab063d75e15fe2ea4f787b5b124659 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Sun, 31 Mar 2024 13:02:06 -0700 Subject: [PATCH 1/2] Fix error in 3.12 during Pytest --- doc/CHANGELOG.rst | 1 + native/python/pyjp_object.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/CHANGELOG.rst b/doc/CHANGELOG.rst index 74451c308..5848e7d66 100644 --- a/doc/CHANGELOG.rst +++ b/doc/CHANGELOG.rst @@ -6,6 +6,7 @@ This changelog *only* contains changes from the *first* pypi release (0.5.4.3) o Latest Changes: - **1.5.1_dev0 - 2023-12-15** + - Fixed uncaught exception while setting traceback causing issues in Python 3.11/3.12. - Use PEP-518 and PEP-660 configuration for the package, allowing editable and configurable builds using modern Python packaging tooling. Where before ``python setup.py --enable-tracing develop``, now can be done with diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index 0de9f9f2c..c059eb376 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -390,7 +390,8 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j { // Attach the frame to first JPPyObject trace = PyTrace_FromJavaException(frame, th, enclosing); - PyException_SetTraceback(exc.get(), trace.get()); + if (trace.get()!=nullptr) + PyException_SetTraceback(exc.get(), trace.get()); // Check for the next in the cause list enclosing = th; From faaaca428dd906a84b259250042e22ff6a6a7df7 Mon Sep 17 00:00:00 2001 From: Karl Nelson Date: Mon, 1 Apr 2024 17:04:14 -0700 Subject: [PATCH 2/2] Fix second uncaught exception --- native/common/jp_exception.cpp | 3 ++- native/python/pyjp_object.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/native/common/jp_exception.cpp b/native/common/jp_exception.cpp index 10cc9c9ec..a99964c69 100644 --- a/native/common/jp_exception.cpp +++ b/native/common/jp_exception.cpp @@ -220,7 +220,8 @@ void JPypeException::convertJavaToPython() PyJPException_normalize(frame, prev, jcause, th); PyException_SetCause(cause.get(), prev.keep()); } - PyException_SetTraceback(cause.get(), trace.get()); + if (trace.get() != nullptr) + PyException_SetTraceback(cause.get(), trace.get()); PyException_SetCause(pyvalue.get(), cause.keep()); } catch (JPypeException& ex) { diff --git a/native/python/pyjp_object.cpp b/native/python/pyjp_object.cpp index c059eb376..ae2ffbe0d 100644 --- a/native/python/pyjp_object.cpp +++ b/native/python/pyjp_object.cpp @@ -390,7 +390,7 @@ void PyJPException_normalize(JPJavaFrame frame, JPPyObject exc, jthrowable th, j { // Attach the frame to first JPPyObject trace = PyTrace_FromJavaException(frame, th, enclosing); - if (trace.get()!=nullptr) + if (trace.get() != nullptr) PyException_SetTraceback(exc.get(), trace.get()); // Check for the next in the cause list