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

Ambiguous method name xxx in class xx #1552

Closed
RichardHoOoOo opened this issue Feb 9, 2021 · 1 comment
Closed

Ambiguous method name xxx in class xx #1552

RichardHoOoOo opened this issue Feb 9, 2021 · 1 comment

Comments

@RichardHoOoOo
Copy link
Contributor

Suppose I have a class A and a class B that extends A. Class B has a method foo that overrides Class A's foo.

class A {
    public A foo() {return null;}
}

class B extends A {
    public B foo() {return null;}
}

When I use the following code to get class B's foo, an exception is thrown saying soot.AmbiguousMethodException: Ambiguous method name foo in class B

SootClass B = Scene.v().loadClassAndSupport("B");
SootMethod fooB = B.getMethodByNameUnsafe("foo");

When I print all the methods in B, the output is

<B: void <init>()>
<B: B foo()>
<B: A foo()>

Since B's foo overrides A's foo, why there are two foos in B that causes the ambiguous exception?

@MarcMil
Copy link
Contributor

MarcMil commented May 31, 2021

I'd guess this is related to #1553
The java compiler probably generates a method to access that other foo of the super class, and thus, there are two methods with the same name. Personally, I'd refrain to use getMethodByNameUnsafe if possible for reasons like this. Besides, overloading methods is very common and would lead to a failure as well. I'd reference methods by their subsignature.

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