Fix crash when isinstance() is called with JException before JVM starts#1436
Open
Thrameos wants to merge 3 commits into
Open
Fix crash when isinstance() is called with JException before JVM starts#1436Thrameos wants to merge 3 commits into
Thrameos wants to merge 3 commits into
Conversation
Fixes issue jpype-project#1329 where calling isinstance(obj, JException) would crash with an unhandled C++ exception when the JVM had not been started or had been shut down. The problem occurred in PyJPClass_instancecheck() which created a JPJavaFrame without first checking if the JVM was running. This caused an unhandled JPypeException to be thrown from C++ code when users tried to wrap exceptions from failed startJVM() calls. The fix adds a JVM running check before creating the frame, following the same pattern already used in PyJPClass_subclasscheck(). When the JVM is not running, the function now falls back to Python-only type checking. Added comprehensive test coverage for: - isinstance() before JVM starts - isinstance() with non-Java objects after JVM starts - isinstance() with actual Java exceptions Co-Authored-By: Claude Sonnet 4 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1436 +/- ##
==========================================
- Coverage 86.24% 86.22% -0.02%
==========================================
Files 112 112
Lines 10289 10289
Branches 4056 4056
==========================================
- Hits 8874 8872 -2
- Misses 809 811 +2
Partials 606 606
🚀 New features to boost your workflow:
|
Contributor
Author
|
@marscher simple change to prevent a raise condition that happened during exception handling. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes issue #1329 where calling isinstance(obj, JException) would crash with an unhandled C++ exception when the JVM had not been started or had been shut down.
The problem occurred in PyJPClass_instancecheck() which created a JPJavaFrame without first checking if the JVM was running. This caused an unhandled JPypeException to be thrown from C++ code when users tried to wrap exceptions from failed startJVM() calls.
The fix adds a JVM running check before creating the frame, following the same pattern already used in PyJPClass_subclasscheck(). When the JVM is not running, the function now falls back to Python-only type checking.
Added comprehensive test coverage for:
Fixes #1329