Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Let the check_exception handler raise the error with more details. #508

Merged
merged 1 commit into from
Apr 19, 2020

Conversation

kollivier
Copy link
Contributor

I've been getting an error loading NativeInvocationHandler class using autoclass in the latest py3+webview bootstrap code for p4a, but the error message didn't contain many details. After investigating, I realized check_exception would give me those details, but the code was raising an exception manually before calling that function.

This PR changes find_javaclass to return the exception generated by catch_exception instead of the currently thrown error.

@cmacdonald
Copy link
Contributor

Hi,
can you show the output with and without the patch?

@kollivier
Copy link
Contributor Author

With the patch:

04-11 22:08:54.480 3718 3718 I python : File "jnius/jnius_export_func.pxi", line 26, in jnius.jnius.find_javaclass
04-11 22:08:54.480 3718 3718 I python : File "jnius/jnius_utils.pxi", line 91, in jnius.jnius.check_exception
04-11 22:08:54.480 3718 3718 I python : jnius.jnius.JavaException: JVM exception occurred: Didn't find class "org.jnius.NativeInvocationHandler" on path: DexPathList[[zip file "/data/app/org.learningequality.Kolibri-2/base.apk"],nativeLibraryDirectories=[/data/app/org.learningequality.Kolibri-2/lib/arm, /data/app/org.learningequality.Kolibri-2/base.apk!/lib/armeabi-v7a, /system/lib, /vendor/lib]]

Without the patch:

04-11 23:23:50.545 17653 17729 I python : File "jnius/jnius_export_func.pxi", line 28, in jnius.jnius.find_javaclass
04-11 23:23:50.545 17653 17729 I python : jnius.jnius.JavaException: Class not found b'org/jnius/NativeInvocationHandler'

Notice that with the patch, it tells me the exact search path it used, which suggests that the issue is that the directory that contains org.jnius.NativeInvocationHandler is not on the search path, even though jnius_config.get_classpath() does include that dir.

BTW, since this problem appears to be specific to the webview bootstrap, I'm going to check into changes that were made to the SDL2 bootstrap that might not have been propagated or made in the same way to the webview bootstrap.

Copy link
Member

@tshirtman tshirtman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, looks good to me, not sure how it came to be this way, but that seems better indeed.

@tshirtman tshirtman merged commit a63331d into kivy:master Apr 19, 2020
tshirtman added a commit that referenced this pull request May 3, 2020
Full Changelog: 1.2.1...1.3.0

Implemented enhancements:
- (#483) allow passing a `signature` argument to constructors, to force selection of the desired one
- (#497) support for more "dunder" methods/protocols on compatible interfaces than just `__len__`, and allow users to provide their own.
- (#500) allow ignoring private methods and fields in autoclass (both default to False)
- (#503) auto detect java_home on OSX, using `/usr/libexec/java_home` (if JAVA_HOME is not declared)
- (#514) writing to static fields (and fix reading from them)
- (#517) make signature exceptions more useful
- (#502) provide a stacktrace for where JVM was started.
- (#523) expose the class's class attribute
- (#524) fix handling of Java chars > 256 in Python3
- (#519) Always show the exception name

Fixed bugs:
- (#481) wrong use of strip on JRE path
- (#465) correct reflection to avoid missing any methods from parent classes or interfaces
- (#508) don't had error details with a custom exception when java class is not found
- (#510) add missing references to .pxi files in setup.py, speeding up recompilation
- (#518) ensure autoclass prefers methods over properties
- (#520) improved discovery of libjvm.so + provide a workaround if it doesn't work

Documentation:
- (#478) document automatic Thread detach feature
- (#512) document the requirement to keep reference to object/functions passed to java, for as long as it might use them
- (#521) fix inheritance in example

Many thanks to the contributors that stepped up to help this release, it wouldn't have been possible without them.

Craig Macdonald, Gabriel Pettier, Jim, André Miras, Young Ryul Bae, yyang, Pascal Chambon, Kevin Ollivier, Guillaume Gay, Christian M. Salamut, collaborated for this release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants