Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 368819 - [implementation] Bogus implementation of Position#equals / Position#hashCode
Summary: [implementation] Bogus implementation of Position#equals / Position#hashCode
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P5 minor (vote)
Target Milestone: ---   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2012-01-17 07:35 EST by Sebastian Zarnekow CLA
Modified: 2019-11-19 03:40 EST (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 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.