question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improvement: autoclass() when class not in boot classpath

See original GitHub issue

I have a slight problem: I’m trying to instantiate a class that is have a java.lang.Class reference to. This was provided by a ClassLoader accessing a classpath different from “boot time”. Traceback attached below.

However, JNI’s FindClass() only provides jclass for classes in the boot classpath, i.e. using ClassLoader.getSystemClassLoader().

I dont think we need FindClass(), as we already have access to the Class object. We just need to instantiate it from that Class object.

  1. A possible workaround is adding an optional parameter to autoclass() providing the Class object directly, i.e.
other_class = bla._class.getClassLoader().loadClass("my.other.Class")
other_classInstance = autoclass(None, cls=other_class)()
  1. Or being able to pass a ClassLoader to autoclass? Dont think this would work in the generic case.

  2. Or detecting when a Class object is being instantiated into Python, add that to jclass_register

Traceback.

Traceback (most recent call last):
  File "tests/test_rewrite.py", line 97, in test_rm3
    qe = pt.rewrite.RM3(indexref)
  File "/Users/craigm/git/Pyterrier/pyterrier/rewrite.py", line 139, in __init__
    rm = pt.ApplicationSetup.getClass("org.terrier.querying.RM3").newInstance()
  File "jnius/jnius_export_class.pxi", line 857, in jnius.JavaMethod.__call__
  File "jnius/jnius_export_class.pxi", line 939, in jnius.JavaMethod.call_method
  File "jnius/jnius_conversion.pxi", line 212, in jnius.convert_jobject_to_python
  File "/Users/craigm/anaconda3/envs/pyterrier/lib/python3.6/site-packages/jnius/reflect.py", line 229, in autoclass
    c = find_javaclass(clsname)
  File "jnius/jnius_export_func.pxi", line 26, in jnius.find_javaclass
  File "jnius/jnius_jvm_dlopen.pxi", line 91, in jnius.create_jnienv
jnius.JavaException: JVM exception occurred: org/terrier/querying/RM3 java.lang.NoClassDefFoundError

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
cmacdonaldcommented, May 6, 2020

“I’m trying to instantiate a class that I have a java.lang.Class reference to.”

Yes, your proposal may work - a variant of (1). Will give a try in due course. Thanks.

0reactions
tshirtmancommented, May 24, 2020

took the liberty to open #539 from it to review more easily.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why classes loaded with boot classloader (bootclasspath ...
JUnit library is added by Eclipse and it goes to regular classpath whenever bootloaded classes doesn't have a way to reference them.
Read more >
n attempt was made to call a method that does not exist. ...
Reason #2 - the application's classpath is incorrectly specified. The second likely cause is that the class name is correct, but that the...
Read more >
API — Pyjnius 1.0a1 documentation - Read the Docs
Represents the Java class name, in the format 'org/lang/Class' (e.g. 'java/util/Stack'), not 'org.lang.Class'. __javaconstructor__ ¶. If not set, we assume the ...
Read more >
Java Guide: How to Fix "Could not find or load main class"
Incorrectly specified classpath of the application. Missing dependencies from the classpath. Incorrect directory path on the classpath. A typo ...
Read more >
Release Notes — Airflow Documentation
Significant Changes; Bug Fixes; Improvements; Doc only changes; Misc ... Moved two classes to different modules; Fixed typo in –driver-class-path in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found