Skip to content

Make FontData key in map of ScalingSWTFontRegistry immutable #218

@fedejeanne

Description

@fedejeanne

As mentioned in point Nr. 3 of #98 (comment) (pasted below), this could lead to problems if someone changes the internal state of fontData.

3. org.eclipse.swt.internal.ScalingSWTFontRegistry.fontKeyMap uses FontData as key

(Same problem for org.eclipse.swt.internal.DefaultSWTFontRegistry.fontsMap).

FontData is not immutable which may lead to information getting lost.

Example

public static void main(String[] args) {
  Map<FontData, String> map = new HashMap<>();

  FontData fontData = new FontData("f1", 10, 10);
  map.put(fontData, "found!");

  System.out.println(map.get(fontData));

  fontData.height += 1;

  System.out.println(map.get(fontData));
}

Produces the output:

found!
null

Task

Make the key in the registry map immutable. Possible options are:

  • Clone the FontData used as key so that no one outside the registry has access to it and may modify it
  • Find some other kind of key that is both unique and immutable

Metadata

Metadata

Labels

HiDPIA HiDPI-Related Issue or FeatureSWTIssue for SWT

Type

Projects

Status

✅ Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions