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

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

Merged

Conversation

dkimitsa
Copy link
Contributor

@dkimitsa dkimitsa commented May 6, 2024

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:

  • if pointer is not resolved to any class -- $ObjCProxy should be used to marshal into interface implementation;
  • even if pointer was resolved to best available class in hierarchy (lets say NSObject), it might be not top one that implement interface itself. As result $ObjCProxy will be used as target class for marshalling.

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

…nted in pure Swift classes

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:
- if pointer is not resolved to any class -- $ObjCProxy should be used to marshal into interface implementation;
- even if pointer was resolved to best available class in hierarchy (lets say NSObject), it might be not top one that implement interface itself. As result $ObjCProxy will be used as target class for marshalling.

## 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
@Tom-Ski Tom-Ski merged commit 1d11deb into MobiVM:master May 7, 2024
1 check passed
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.

2 participants