shannah / Java-Objective-C-Bridge

A thin bridge that allows for two-way communication from Java to Objective-C.
123 stars 25 forks source link

Problems updating to Java 11 #13

Closed schlachtzeuger closed 4 years ago

schlachtzeuger commented 5 years ago

Hi there,

I'm currently trying to update a project to Java 11, but ran into issues I can't solve by myself.

In the Objective-C code, I have a class containing a property defined as:

@property (readonly, strong) NSString *identifier;

This is how the bridging code in Java looks like:

public String getId() { return proxy.sendString("identifier"); }

While calling this method in Java 8 works perfectly, it throws an exception in Java 11:

Exception in thread "main" java.lang.ClassCastException: class ca.weblite.objc.Proxy cannot be cast to class java.lang.String (ca.weblite.objc.Proxy is in unnamed module of loader 'app'; java.lang.String is in module java.base of loader 'bootstrap') at ca.weblite.objc.Proxy.sendString(Proxy.java:229) at ca.weblite.objc.Proxy.sendString(Proxy.java:233) at net.test.someproject.SomeClass.getId(ObjCCommand.java:22) at net.test.someotherproject.TestMain.main(TestMain.java:275)

If I used instead proxy.send("identifier"), it returns a Proxy object in Java 11. In Java 8, this is a String object.

Thanks for your help!

Max

mojo2012 commented 5 years ago

This should be solved in the current master branch! The problem was that the NSString mapping was hardcoded for that exact class name.

schlachtzeuger commented 5 years ago

Cool, thanks for the info! I will try it out soon. But why was this no problem on older Java runtimes?

mojo2012 commented 5 years ago

Tbh, I didn't look into it in more detail. Just debugged to the class where the mapping happens and saw that a different NSString class was passed. I haven't used java8 for quite some time now (thank god :-D)

mojo2012 commented 4 years ago

@schlachtzeuger does it work for you now, so we can close this ticket?

schlachtzeuger commented 4 years ago

@mojo2012 Sorry that I did not answer yet. Yes, I tried it and it works perfectly! Thanks for your help =)