Skip to content

fix: prevent duplicate font family entries in FontFactoryImp - #1623

Open
garcia-d wants to merge 1 commit into
LibrePDF:2.0-java17from
garcia-d:fix/2.0-java17/fontfamily-duplicate-registration
Open

garcia-d wants to merge 1 commit into
LibrePDF:2.0-java17from
garcia-d:fix/2.0-java17/fontfamily-duplicate-registration

Conversation

@garcia-d

@garcia-d garcia-d commented Sep 14, 2026

Copy link
Copy Markdown

Description of the new Feature/Bugfix

FontFactoryImp.registerFamily appended a [familyName, fullName] pair to
its internal family list on every call, even when that exact pair was
already registered. Repeated registration of the same font grew the list
unboundedly and slowed down font lookup over time.

Guarded the insertion path with a contains check so the same
familyName/fullName pair is only ever added once. Added a package-private
getRegisteredFamily accessor and a unit test covering the deduplication
invariant.

Related Issue: none (found during code review, not tied to a filed issue)

Unit-Tests for the new Feature/Bugfix

  • Unit-Tests added to reproduce the bug
  • Unit-Tests added to the added feature

Compatibilities Issues

No behavioral change for callers - registerFamily still registers the
pair, just without duplicating it on repeat calls. No existing method
signatures changed; getRegisteredFamily is a new package-private
accessor, added only for the test.

Your real name

Diego Garcia

Testing details

Added FontFactoryImpTest coverage for the dedup invariant. Full
openpdf test suite run locally with no regressions.

🤖 Generated with Claude Code

Guard the registerFamily insertion path with a contains check so that
calling registerFamily with the same familyName/fullName pair more than
once does not grow the family list unboundedly and slow down font lookup.

Add a package-private getRegisteredFamily accessor and a unit test to
cover the deduplication invariant.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 111 complexity · 4 duplication

Metric Results
Complexity 111
Duplication 4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@garcia-d

Copy link
Copy Markdown
Author

Hi @asturio,

This PR backports the font family duplicate-registration fix to the 2.0-java17 branch. The same fix has been opened for every active branch: #1621 (1.3-java8), #1622 (1.4-java11), #1624 (2.2-java21), #1625 (2.4), #1626 (master).

Whenever you get a chance, I'd appreciate your review, and if it looks good, approval/merge into 2.0-java17.

I'd also kindly ask, once merged, if an official release including this fix could be cut — particularly for the Java 8-compatible line (#1621), since I'd rather rely on an official release than patch it in locally.

Thanks for maintaining OpenPDF!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant