iOS13 PostFix #4: Compilation failed on @Bridge annotate covariant return synthetic method22 Oct 2019 | fix compiler postfix
This post continues the series of fixes discovered during compilation of CocoaTouch library.
PostFix #4: @Bridge annotated covatiant return bridget methods
- PostFix #1: Generic class arguments and @Block parameters
- PostFix #2: Adding support for non-static @Bridge method in enums classes
- PostFix #3: Support for @Block member in structs
- PostFix #5: Support for Struct.offsetOf in structs
- PostFix #6: Fixes to Network framework bindings
- PostFix #7: bindings for ios13.2
- PostFix #8: workaround for missing objc classes(ObjCClassNotFoundException)
- PostFix #9: experimental and formal bitcode support
- PostFix #10: glkit – missing functions (static inline now)
Issue was discovered while compiling
java.lang.IllegalArgumentException: @Bridge annotated method <org.robovm.apple.network.NWTxtRecord: org.robovm.apple.foundation.NSObject copy()> must be native at org.robovm.compiler.BridgeMethodCompiler.validateBridgeMethod(BridgeMethodCompiler.java:87) at org.robovm.compiler.BridgeMethodCompiler.doCompile(BridgeMethodCompiler.java:233)
Root case and fix
In source code
NWTxtRecord doesn’t contain
NSObject copy() method but containts
Hovewer once class file is decompiled following methods can be found there:
public native org.robovm.apple.network.NWTxtRecord copy(); descriptor: ()Lorg/robovm/apple/network/NWTxtRecord; flags: (0x0101) ACC_PUBLIC, ACC_NATIVE RuntimeVisibleAnnotations: org.robovm.rt.bro.annotation.Bridge(symbol="nw_txt_record_copy") public org.robovm.apple.foundation.NSObject copy(); descriptor: ()Lorg/robovm/apple/foundation/NSObject; flags: (0x1041) ACC_PUBLIC, ACC_BRIDGE, ACC_SYNTHETIC RuntimeVisibleAnnotations: org.robovm.rt.bro.annotation.Bridge(symbol="nw_txt_record_copy") Code: stack=1, locals=1, args_size=1 0: aload_0 1: invokevirtual #13 // Method copy:()Lorg/robovm/apple/network/NWTxtRecord; 4: areturn
NSObject copy() is present in class file and was added there by
javac to handle overriden method with covariant return type. As
NSObject at some level and
copy() method with return type that covariant to
NWTxtRecord. More details in Oracle’s document.
RoboVM compiler finds
@Bridge annotation on this synthetic method (as these being copied since JDK-6695379) and tries to handle it as a @Bridge to native founction and it fails as method doesn’t match the criteria (currently it is not native).
There are two way of fix:
- simple, as @Bridge methods are just binding for native function the name of method might be changed to eliminate override with covariant return type case;
- modify the compiler to handle these methods, skips them actually.
Second approach was implemented and delivered as PR422