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

fix ambiguous/wrong origins for calls from bridge methods #714

Merged
merged 1 commit into from
Nov 6, 2021

Conversation

codecholeric
Copy link
Collaborator

Originally we assumed that comparing declaring class, method name and parameter type names would be good enough to identify the caller of a method, since the compiler does not allow to declare two methods with the same name and parameter types inside the same class. However, the compiler might add methods with the same name and parameter types in certain cases (bridge methods).
Consider

class Parent {
  Object method() {
    return null;
  }
}

class Child extends Parent {
  @Override
  String method() {
    return null;
  }
}

To implement covariant return types (the child overriding the method using a subtype as return type) the compiler transparently adds a so-called "bridge method" that has the original type as return type (i.e. overrides 1-2-1) and simply forwards to the one with the subtype as return type.
We now take the full descriptor (containing parameter types and return types) to match the origin of a caller. By that the ambiguity is resolved, since the descriptor/full signature actually has to be unique.

Resolves: #513

@codecholeric codecholeric force-pushed the fix-ambiguous-call-origins branch 2 times, most recently from 0a6c6b2 to a34ab28 Compare November 6, 2021 09:00
Originally we assumed that comparing declaring class, method name and parameter type names would be good enough to identify the caller of a method, since the compiler does not allow to declare two methods with the same name and parameter types inside the same class. However, the compiler might add methods with the same name and parameter types in certain cases (bridge methods).
Consider

```
class Parent {
  Object method() {
    return null;
  }
}

class Child extends Parent {
  @OverRide
  String method() {
    return null;
  }
}
```

To implement covariant return types (the child overriding the method using a subtype as return type) the compiler transparently adds a so-called "bridge method" that has the original type as return type (i.e. overrides 1-2-1) and simply forwards to the one with the subtype as return type.
We now take the full descriptor (containing parameter types and return types) to match the origin of a caller. By that the ambiguity is resolved, since the descriptor/full signature actually has to be unique.

Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric merged commit c6710e7 into main Nov 6, 2021
@codecholeric codecholeric deleted the fix-ambiguous-call-origins branch November 6, 2021 11:29
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.

Covariant return types cause non-deterministic JavaCalls
1 participant