Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 320484 - Weak FontData hashCode
Summary: Weak FontData hashCode
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6   Edit
Hardware: PC Linux-GTK
: P3 normal (vote)
Target Milestone: 3.7 M1   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-21 06:46 EDT by Ralf Sternberg CLA
Modified: 2010-08-04 11:16 EDT (History)
3 users (show)

See Also:


Attachments
fix (4.30 KB, patch)
2010-07-28 11:03 EDT, Silenio Quarti CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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