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

Multiple inheritance on MOE bindings not working when overriding method with annotations only in the last class #182

Open
Berstanio opened this issue Aug 18, 2022 · 1 comment

Comments

@Berstanio
Copy link

Proguard desugaring seems to have a bug with default methods and parameter annotation. Lets assume we have class "TestClass1" with:

import apple.uikit.protocol.UIApplicationDelegate;

public class TestClass1 implements UIApplicationDelegate {
}

Than proguard desugars the default methods of UIApplicationDelegate by copying them to TestClass1. But on default methods with parameter annotations, proguard emits a empty ParameterAnnotations section:
(with javap you will see on a example code)

   RuntimeInvisibleAnnotations:
     0: #103()
       org.moe.natj.general.ann.Generated
   RuntimeVisibleAnnotations:
     0: #108()
       org.moe.natj.objc.ann.IsOptional
     1: #110(#276=s#150)
       org.moe.natj.objc.ann.Selector(
         value="application:performFetchWithCompletionHandler:"
       )
   RuntimeVisibleParameterAnnotations:

However, this is incorrect! It should either be no ParameterAnnotations section at all, or:

    RuntimeInvisibleAnnotations:
      0: #103()
        org.moe.natj.general.ann.Generated
    RuntimeVisibleAnnotations:
      0: #108()
        org.moe.natj.objc.ann.IsOptional
      1: #110(#276=s#150)
        org.moe.natj.objc.ann.Selector(
          value="application:performFetchWithCompletionHandler:"
        )
    RuntimeVisibleParameterAnnotations:
      parameter 0:
      parameter 1:

Even this is broken bytecode, dx/dex2oat seems to still process it.

When we than have another class "TestClass2" with the following:

import apple.uikit.UIApplication;

public class TestClass2 extends TestClass1 {
    @Override
    public void applicationPerformFetchWithCompletionHandler(UIApplication application,
            Block_applicationPerformFetchWithCompletionHandler completionHandler) {
    }
}

Now when the classvalidator runs after the desugaring, it tries to copy the annotations from the parent implemenation. But since java is more strict, a "java.lang.annotation.AnnotationFormatError: Parameter annotations don't match number of parameters" exception is thrown.

Also, I don't know whether or when you plan to merge/take a look at the r8 stuff, but that should also fix the issue.

@Berstanio Berstanio changed the title Multiple inheritance on MOE bindings not working Multiple inheritance on MOE bindings not working when overriding method with annotations only in the last class Aug 18, 2022
@andre719mv
Copy link

andre719mv commented Apr 20, 2024

In my case function was defined in TestClass1, but it was defined as abstract. Adding of missed annotations did not help. Fix that worked for me:
image

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

No branches or pull requests

2 participants