Skip to content

Cannot add annotations to JCW for methods that implement interface methods #11853

Closed

Description

@jpobst

Context: dotnet/maui@0820530
Context: #7714

Imagine that you have the following Java interface and annotation:

public interface DoSomething {
  void do ();
}

public abstract interface JavascriptInterface implements Annotation { }

You want to implement DoSomething.Do () in C# and apply the [JavascriptInterface] attribute to it, hoping the @JavascriptInterface Java annotation will be added to your JCW method.

public class MyClass : Java.Lang.Object, IDoSomething {
  [JavascriptInterface]
  public void Do () { ... }
}

If Do () was an override to a Java class method this would work. However when we generate JCWs for implemented interface methods, we do not consider what the user has written. We (correctly) assume that the user has provided an implementation for every required interface method. That is, we generate a JCW method for every method we find on implemented interfaces.

Because we ignore what the user has written when generating the JCW method, we will not see that they have added an attribute to their method, and we will not add the requested Java annotation to the JCW method.

To fix this, we need to figure out which methods in the user's code implements an interface method so we can apply any attributes the user has added to the JCW method.

Note that the implementation for this is likely quite complex. We will have to build a map between the user's methods and the implemented interface methods so we can determine which user methods are interface implementations and which aren't. This also gets more complicated with things like generics, explicit interface implementations, and default interface methods.

Activity

  1. added
    bugComponent does not function as intended.
    on Sep 30, 2024
  2. added theissue type on Apr 29, 2025
  3. removed
    bugComponent does not function as intended.
    on Apr 29, 2025
  4. added
    java-interopIssues migrated from dotnet/java-interop / relates to the Java.Interop subtree
    needs-triageIssues that need to be assigned.
    Area: BindingsIssues in Java Library Binding projects.
    on Jul 1, 2026
  5. dotnet-policy-service commented on Jul 1, 2026

    @dotnet-policy-service

    We suspect this issue is stale and no longer relevant. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.

  6. dotnet-policy-service commented on Jul 15, 2026

    @dotnet-policy-service

    This issue will now be closed since it had been marked "possibly-stale" but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.

  7. locked and limited conversation to collaborators on Aug 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: BindingsIssues in Java Library Binding projects.java-interopIssues migrated from dotnet/java-interop / relates to the Java.Interop subtreeneeds-triageIssues that need to be assigned.possibly-staleIssues that are potentially no longer relevant.

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions