A couple of classes in the `sun.font` package could use additional immutability 
guarantees:

- The `ExtendedTextSourceLabel` class needs to be immutable (and not extendable 
as a mutable subclass) so that the optimization (returning `this`) in 
`ExtendedTextSourceLabel.getSubset(int, int, int)` is safe. This was brought up 
in the review for [JDK-8356814](https://bugs.openjdk.org/browse/JDK-8356814).

- The `SDKey`/`SDCache` cache in `GlyphLayout$SDCache` also benefits from 
immutable components. `SDKey` is already immutable, but `SDCache` could benefit 
at least from some shallow immutability.

Note that part of making the cached attributes in `ExtendedTextSourceLabel` 
final involved the deletion of the unused constructor, and folding of the 
`finishInit()` method into the sole remaining constructor.

No regressions seen locally in `make test TEST="jtreg:test/jdk/java/awt/font"` 
or `make test TEST="jtreg:test/jdk/java/awt/Graphics2D/DrawString"` on 
Linux/Windows/macOS.

-------------

Commit messages:
 - Minimize diff
 - Additional immutability in sun.font: ExtendedTextSourceLabel, GlyphLayout

Changes: https://git.openjdk.org/jdk/pull/30565/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=30565&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8381623
  Stats: 37 lines in 2 files changed: 7 ins; 20 del; 10 mod
  Patch: https://git.openjdk.org/jdk/pull/30565.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/30565/head:pull/30565

PR: https://git.openjdk.org/jdk/pull/30565

Reply via email to