Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 368819

Summary: [implementation] Bogus implementation of Position#equals / Position#hashCode
Product: [Eclipse Project] Platform Reporter: Sebastian Zarnekow <sebastian.zarnekow>
Component: TextAssignee: Platform-Text-Inbox <platform-text-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: minor    
Priority: P5 CC: daniel_megert
Version: 3.5   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard: stalebug

Description Sebastian Zarnekow CLA 2012-01-17 07:35:12 EST
from org.eclipse.jface.text.Position v 3.5.200

	 /*
	 * @see java.lang.Object#hashCode()
	 */
	public int hashCode() {
	 	int deleted= isDeleted ? 0 : 1;
	 	return (offset << 24) | (length << 16) | deleted;
	}

	/*
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object other) {
		if (other instanceof Position) {
			Position rp= (Position) other;
			return (rp.offset == offset) && (rp.length == length);
		}
		return super.equals(other);
	}

the deleted state is part of the hashCode but not considered in the equals implementation thus two equal position may yield different hashCode. I think this is a bug.
Comment 1 Dani Megert CLA 2012-01-17 08:10:18 EST
> the deleted state is part of the hashCode but not considered in the equals
> implementation thus two equal position may yield different hashCode. I think
> this is a bug.

Yes, it violates the hashCode() contract. However, it's like that since 1.0. Do you have a concrete/existing scenario where the current implementation is causing a problem?
Comment 2 Sebastian Zarnekow CLA 2012-01-17 08:14:40 EST
No, there was no concrete problem and I could not find any code snippets that relied on a working hashCode / equals semantic since almost all clients search positions by offset.

However, I wanted to report it for further investigation.
Comment 3 Lars Vogel CLA 2019-11-14 03:31:32 EST
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.

If the bug is still relevant, please remove the "stalebug" whiteboard tag.
Comment 4 Sebastian Zarnekow CLA 2019-11-19 03:40:20 EST
Nothing will be changed about this.