Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 540890 - [hashcode/equals] generated "Java 7" hashcode should use the parent hashcode
Summary: [hashcode/equals] generated "Java 7" hashcode should use the parent hashcode
Status: CLOSED DUPLICATE of bug 539589
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.9   Edit
Hardware: PC Windows 10
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-07 11:38 EST by Simon Lefebvre CLA
Modified: 2018-11-07 12:34 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 Simon Lefebvre CLA 2018-11-07 11:38:25 EST
There is a inconsistency between the legacy generated hashCode and the new "Java 7" generated hashCode :

Legacy : 
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((param1 == null) ? 0 : param1.hashCode());
		result = prime * result + ((param2 == null) ? 0 : param2.hashCode());
		return result;
	}

Java 7 :
	@Override
	public int hashCode() {
		return Objects.hash(param1, param2);
	}

The new version does not take in account the super.hashCode() in the computation, leading to inconsistency between generated hashCode and equals.

I think the Java 7 version should be somethings like this :
	@Override
	public int hashCode() {
		return 31 * super.hashCode() + Objects.hash(param1, param2);
	}
Comment 1 Till Brychcy CLA 2018-11-07 12:34:46 EST
Thanks for reporting, that is already fixed for 4.10

*** This bug has been marked as a duplicate of bug 539589 ***