MobiVM / robovm

Ahead of time compiler for JVM bytecode targetting iOS, Mac OSX and Linux
https://mobivm.github.io
942 stars 132 forks source link

* fixed: ObjCClassNotFoundException when marshaling protocols implemented in pure Swift classes #784

Closed dkimitsa closed 2 months ago

dkimitsa commented 2 months ago

reported over gitter, in scope of CleverAds:

"Terminating app due to uncaught exception 'org.robovm.objc.ObjCClassNotFoundException', reason: 'org.robovm.objc.ObjCClassNotFoundException: Could not find Java class corresponding to Objective-C class: CleverAdsSolutions.ImpressionWrapper".

Root case

Then trying to marshal pointer to Java world and turn it into Interface instance ObjC runtime tries find as much complete as possible class instance representation from this pointer to allow to have not just as $ObjCProxy of this interface/protocol but a proper class instance.

In case of reported issue: there was expected CASStatusHandler protocol in callback. CAS provided pure Swift class CleverAdsSolutions.ImpressionWrapper that implemented it. This class is extended from Swift._SwiftObject and this class is not known to RoboVM as well. As result everything was terminated with: ObjCClassNotFoundException

What is wrong here:

The fix:

consider ObjCClassNotFoundException case similar to not isAssignableFrom and use $ObjCProxy in both case. changes were done to not throw ObjCClassNotFoundException in case class being resolved on behalf of $ObjCProxy