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

Bug 320484

Summary: Weak FontData hashCode
Product: [Eclipse Project] Platform Reporter: Ralf Sternberg <rsternberg>
Component: SWTAssignee: Silenio Quarti <Silenio_Quarti>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: eclipse.felipe, pinnamur, Silenio_Quarti
Version: 3.6   
Target Milestone: 3.7 M1   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
fix none

Description Ralf Sternberg CLA 2010-07-21 06:46:38 EDT
The following font datas all produce the same hash code:

new FontData( "Times", 15, SWT.NORMAL ).hashCode();
new FontData( "Times", 14, SWT.BOLD ).hashCode();
new FontData( "Times", 13, SWT.ITALIC ).hashCode();
new FontData( "Times", 12, SWT.BOLD | SWT.ITALIC ).hashCode();

This can be fixed by changing FontData hashCode from:

	return name.hashCode() ^ getHeight() ^ style;

to:

	return name.hashCode() ^ getHeight() << 2 ^ style;
Comment 1 Silenio Quarti CLA 2010-07-28 11:03:12 EDT
Created attachment 175415 [details]
fix
Comment 2 Silenio Quarti CLA 2010-07-28 11:18:47 EDT
FontData is not serializable, so changing the hash code should not cause problems.

Fixed > 20100728