-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Meta Object loading system doesn't use custom classloaders - can't find classes from downloaded jars #92
Comments
It's defiitely not Try to put your downloaded jar into following property: System.setProperty("io.qt.qtjambi.internal.urlbase", "path to jar file"); QtJambi should now be able to load classes from the URL. |
del |
Thanks, that workaround worked. Could you please also fix the qtjambi_class_for_metatype issue in the next release? (not p1 urgent now) |
The next release will save class references instead of class names for QMetaTypes. Thus, no need to find these classes in whatever classloader. Also I will remove the |
Describe the bug
If you use a custom classloader, for example when some of your classes are in downloaded jar, jambi uses the most basic default classloader and it fails to download any classes from that jar.
To Reproduce
This is just one example of the bug, feature.partitions.PortfolioPartitionScope class is in downloaded jar.
2022-10-18 15:54:08.309 [LS] ERROR [JTS-Main] - Got nested exception in qt event
java.lang.ClassNotFoundException: feature.partitions.PortfolioPartitionScope
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at io.qt.core.QMetaType.qRegisterMetaType(Native Method)
at io.qt.internal.QtJambiInternal.registerMetaType(QtJambiInternal.java:2794)
at io.qt.internal.MetaObjectTools.buildMetaData(MetaObjectTools.java:1297)
at io.qt.core.QAbstractTableModel.initialize_native(Native Method)
at io.qt.core.QAbstractTableModel.(QAbstractTableModel.java:57)
at io.qt.core.QAbstractTableModel.(QAbstractTableModel.java:49)
at ibkr.portfolio.PortfolioPositionsModelView.(PortfolioPositionsModelView.java:485)
We set all threads with classloader that knows about the sdownloaded jar, but QMetaType.qRegisterMetaType is not using these overridden classloaders.
We also tried changing system classloader using -Djava.system.class.loader=YourClassloader - QMetaType.qRegisterMetaType does not use that classloader too..
Expected behavior
.QMetaType.qRegisterMetaType must correctly use Thread classloader, or in the worst case at least use classloader passed from -Djava.system.class.loader
System (please complete the following information):
Additional context
We belive this happens because in most places like
qtjambimetaobject.cpp
jclass QtJambiMetaObject::javaClass()
a simpleenv->FindClass(getJavaName(*typeId))
is used, that does not look for any thread attached classloaders or overidden system classloader and intead simply uses jdk.internal.loader.BuiltinClassLoader.Correct implementation should look like in
qtjambi_registry.cpp
jclass findClass(JNIEnv *env, const char *qualifiedName, jobject classLoader = nullptr)
- it actually checks for thread classloader and uses it if default one didn't find the class.Please use similar approach for classes that you load in QMetaType.qRegisterMetaType
If possible, please replace all
env->FindClass()
calls with correct implemntation that checks for custom classloaderThe text was updated successfully, but these errors were encountered: