eclipse-jdt / eclipse-jdt/eclipse.jdt.core
`BinaryMethod#getSourceRange` may select wrong range for overloaded method
- Dominant language
- Java
- Stars
- 237
- Forks
- 195
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 47
Description
Originally filed as https://bugs.eclipse.org/bugs/show_bug.cgi?id=550625
Given a library that contains a class like:
```java
class DateUtil {
public static void clearTime(java.util.Date) { ... }
public static void clearTime(java.sql.Date) { ... }
}
```
An instance of `BinaryMethod` for `clearTime(java.util.Date)` will always return the source range for the `java.sql.Date` method from `BinaryMethod.getSourceRange()`. When computing `hashCode()` in `BinaryMethod`, the erased parameter types are incorporated. For both methods in the example, the param type is `QDate;`, so the same hash code is produced.
Within `SourceMapper`, there is no extra handling for a key that maps to multiple values:
```java
/**
* Returns the SourceRange for the given element, or
* {-1, -1} if no source range is known for the element.
*/
public SourceRange getSourceRange(IJavaElement element) {
...
SourceRange[] ranges = (SourceRange[]) this.sourceRanges.get(element);
if (ranges == null) {
return UNKNOWN_RANGE;
} else {
return ranges[0]; // XXX: gets here with 2 items in the array
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.