javaparser / javaparser/javaparser
Method Resolution: Respecting Visibility in the Call Context
- Dominant language
- Java
- Stars
- 6.1k
- Forks
- 1.3k
- Avg merge
- 17h 36m
- Merged PRs (30d)
- 28
Description
When attempting to resolve the call `a.m(1)` in the example below, JP correctly identifies the two possible candidates (`m(int)` and `m(long)`) and correctly treats `m(int)` as the most specific, which ought to be selected.
However, in this case, `m(long)` must be selected, because `m(int)` is not visible to `B`.
```java
final class A {
public byte m(long i) { return 2; }
private int m(int i) { return 1; }
}
final class B {
static int callM() {
A a = new A();
return a.m(1);
}
}
```
I did take a cursory look at the code and it seems that the information of where the call originates is lost during resolution. Is this a JP bug or am I simply using the wrong method resolution method(s)?
Contributor guide
Research direction
Start by reproducing the `a.m(1)` example and tracing JavaParser's method-resolution path for the call originating in `B`. Check where the call context and method visibility are considered; done means resolving the visible `m(long)` rather than private `m(int)` and adding a regression test for this case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100