Skip to content

Conversation

@LonelyMidoriya
Copy link
Contributor

@LonelyMidoriya LonelyMidoriya commented Dec 8, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Prevented crashes when processing TrueType fonts with missing or incomplete character mapping data; the renderer now safely falls back to a zero width for unmapped glyphs, avoiding errors for both standard and symbolic mappings.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Dec 8, 2025

Walkthrough

Added null checks for the CmapParser in TrueTypeFontProgram: getWidth and getWidthSymbolic now return 0 when the parser is null; otherwise they obtain a glyph ID from the CmapParser and use getWidthWithCheck(gid).

Changes

Cohort / File(s) Summary
Null-safety in TrueType font width resolution
src/main/java/org/verapdf/pd/font/truetype/TrueTypeFontProgram.java
Added null checks for parser.getCmapParser() in getWidth(int code) and getWidthSymbolic(int code). If CmapParser is null the methods return 0; otherwise they derive glyph ID from the CmapParser and call getWidthWithCheck(gid) to obtain width.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify both null-check branches correctly handle absent CmapParser and don't alter other code paths.
  • Confirm returning 0 is an acceptable fallback for both methods in upstream usage.
  • Check for any logging or diagnostics that should accompany the fallback to aid troubleshooting.

Poem

A rabbit nibbles at a missing map,
Hops past nulls with a gentle tap,
If Cmap’s gone and cannot be found,
I return a zero, safe and sound. 🐇✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: adding null checks before calling getGID() on CmapParser to prevent NullPointerException.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch null-cmap

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a2c1c0 and eb5ab7d.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/pd/font/truetype/TrueTypeFontProgram.java (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/java/org/verapdf/pd/font/truetype/TrueTypeFontProgram.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/main/java/org/verapdf/pd/font/truetype/TrueTypeFontProgram.java (1)

227-228: Apply the same null check here to prevent NPE.

This code has the same NPE risk that was fixed in the getWidth method above. The getCmapParser() call should be null-checked before invoking getGID().

Apply this diff to add consistent null handling:

-        gid = this.parser.getCmapParser().getGID(code);
-        return getWidthWithCheck(gid);
+        if (this.parser.getCmapParser() == null) {
+            return 0;
+        }
+        gid = this.parser.getCmapParser().getGID(code);
+        return getWidthWithCheck(gid);
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6ccfa77 and 8a2c1c0.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/pd/font/truetype/TrueTypeFontProgram.java (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis

@MaximPlusov MaximPlusov merged commit b8eb725 into integration Dec 8, 2025
9 checks passed
@MaximPlusov MaximPlusov deleted the null-cmap branch December 9, 2025 19:09
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.

3 participants