Bug 550625 - BinaryMethod.getSourceRange may select wrong range for overloaded method
Summary: BinaryMethod.getSourceRange may select wrong range for overloaded method
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.13   Edit
Hardware: PC Windows 7
: P3 normal with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2019-08-31 11:28 EDT by Eric Milles CLA
Modified: 2023-08-22 04:50 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Milles CLA 2019-08-31 11:28:36 EDT
Give a library that contains a class like:
    class DateUtil {
      static void clearTime(java.util.Date) { ... }
      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().

Within SourceMapper, there is no extra handling for a key that maps to multiple values:

	/**
	 * Returns the <code>SourceRange</code> 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]; // gets here with 2 items in the array
		}
	}
Comment 1 Eric Milles CLA 2019-08-31 11:30:41 EDT
Bug 441489 shows what the Java editor does in this situation.  In the Groovy editor, the specific method element can be unambiguously found, but SourceMapper cannot resolve the correct source range.
Comment 2 Eric Milles CLA 2019-08-31 11:44:08 EDT
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.
Comment 3 Eclipse Genie CLA 2021-08-24 06:22:01 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 4 Mauro Molinari CLA 2021-08-29 06:37:28 EDT
Eric, do you think this still applies?
Comment 5 Eclipse Genie CLA 2023-08-22 04:50:51 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.