Skip to content

Add new constants to ASAtom#696

Merged
MaximPlusov merged 3 commits intointegrationfrom
asatom-names
Apr 2, 2026
Merged

Add new constants to ASAtom#696
MaximPlusov merged 3 commits intointegrationfrom
asatom-names

Conversation

@LonelyMidoriya
Copy link
Copy Markdown
Contributor

@LonelyMidoriya LonelyMidoriya commented Apr 2, 2026

Summary by CodeRabbit

  • New Features
    • Added two new atom types: "Figure" and "Formula" to expand document atom values.
    • Added a utility to determine whether an annotation lies entirely outside a page crop box; returns true/false or indeterminate when annotation rectangle data is missing or invalid.

@LonelyMidoriya LonelyMidoriya self-assigned this Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Walkthrough

Added two public static ASAtom constants to org.verapdf.as.ASAtom (FIGURE = "Figure", FORMULA = "Formula") and introduced public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) in org.verapdf.pd.PDAnnotation to compare an annotation rect with a page crop box, returning null if the rect is invalid.

Changes

Cohort / File(s) Summary
ASAtom constants
src/main/java/org/verapdf/as/ASAtom.java
Added two new public static ASAtom constants: FIGURE ("Figure") and FORMULA ("Formula"). No other logic changes.
Annotation / Crop-box check
src/main/java/org/verapdf/pd/PDAnnotation.java
Added public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) which reads a page crop box and an annotation Rect array, performs axis-aligned rectangle overlap checks, and returns true/false or null if the annotation rect is missing/invalid.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • MaximPlusov

Poem

🐰 I hop through code with nimble paws,
Two atoms added—no big cause.
I peek at rects and crop-box frames,
A tiny check, precise and tame.
Hooray for small, dependable gains!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title 'Add new constants to ASAtom' directly describes the main change—adding FIGURE and FORMULA constants to ASAtom—but does not mention the secondary change of adding a new method to PDAnnotation.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch asatom-names

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
Copy Markdown

@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.

🧹 Nitpick comments (2)
src/main/java/org/verapdf/pd/PDAnnotation.java (2)

286-286: Use the existing getRect() method instead of duplicating the logic.

The class already has a getRect() method (line 134-136) that performs the exact same call. Reusing it improves maintainability.

♻️ Proposed refactor
     public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
         double[] cropBox = page.getCropBox();
-        double[] rectangle = TypeConverter.getRealArray(annotation.getKey(ASAtom.RECT), 4, "Rect");
+        double[] rectangle = annotation.getRect();
         if (rectangle != null && rectangle.length >= 4) {
             return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
                     || cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
         }
         return null;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/verapdf/pd/PDAnnotation.java` at line 286, Replace the
duplicated rectangle extraction with the existing accessor: instead of calling
TypeConverter.getRealArray(annotation.getKey(ASAtom.RECT), 4, "Rect") directly,
call the PDAnnotation.getRect() method to obtain the rectangle; update any
variable name or usage expecting the double[] from the direct call to use the
value returned by getRect() to avoid duplicate logic and improve
maintainability.

284-292: Consider adding null checks for page and annotation parameters.

If either parameter is null, the method will throw a NullPointerException at the first access. Either add defensive null checks or document the non-null precondition with @param Javadoc.

🛡️ Option: Add null guards returning null
     public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
+        if (page == null || annotation == null) {
+            return null;
+        }
         double[] cropBox = page.getCropBox();
-        double[] rectangle = TypeConverter.getRealArray(annotation.getKey(ASAtom.RECT), 4, "Rect");
+        double[] rectangle = annotation.getRect();
         if (rectangle != null && rectangle.length >= 4) {
             return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
                     || cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
         }
         return null;
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/verapdf/pd/PDAnnotation.java` around lines 284 - 292, The
method isOutsideCropBox lacks null checks for its parameters and will NPE when
page or annotation is null; add defensive guards at the start of
isOutsideCropBox(PDPage page, PDAnnotation annotation) to return null (or
document non-null precondition) if page==null or annotation==null, and ensure
you only call page.getCropBox() and
TypeConverter.getRealArray(annotation.getKey(ASAtom.RECT), ...) after those
checks; keep existing behavior of returning null when rect is missing.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/java/org/verapdf/pd/PDAnnotation.java`:
- Line 286: Replace the duplicated rectangle extraction with the existing
accessor: instead of calling
TypeConverter.getRealArray(annotation.getKey(ASAtom.RECT), 4, "Rect") directly,
call the PDAnnotation.getRect() method to obtain the rectangle; update any
variable name or usage expecting the double[] from the direct call to use the
value returned by getRect() to avoid duplicate logic and improve
maintainability.
- Around line 284-292: The method isOutsideCropBox lacks null checks for its
parameters and will NPE when page or annotation is null; add defensive guards at
the start of isOutsideCropBox(PDPage page, PDAnnotation annotation) to return
null (or document non-null precondition) if page==null or annotation==null, and
ensure you only call page.getCropBox() and
TypeConverter.getRealArray(annotation.getKey(ASAtom.RECT), ...) after those
checks; keep existing behavior of returning null when rect is missing.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 90aa3525-5c2c-4525-b166-df5410acdf6f

📥 Commits

Reviewing files that changed from the base of the PR and between a9c6008 and 0f220b2.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/pd/PDAnnotation.java

Copy link
Copy Markdown

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/main/java/org/verapdf/pd/PDAnnotation.java`:
- Around line 284-292: The method PDAnnotation.isOutsideCropBox currently checks
rectangle for null/length but not cropBox; add a null and length guard for the
cropBox returned by PDPage.getCropBox() (similar to rectangle) before indexing
cropBox[0]..[3], and return null if cropBox is null or has length < 4; update
the conditional that computes the boolean to only run when both cropBox and
rectangle are non-null and length >= 4 (method names: isOutsideCropBox,
PDPage.getCropBox, local variables: cropBox, rectangle).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 80c34da4-edb1-4ebe-9c39-78238981f67a

📥 Commits

Reviewing files that changed from the base of the PR and between 0f220b2 and 0d4584a.

📒 Files selected for processing (1)
  • src/main/java/org/verapdf/pd/PDAnnotation.java

Comment on lines +284 to +292
public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
double[] cropBox = page.getCropBox();
double[] rectangle = annotation.getRect();
if (rectangle != null && rectangle.length >= 4) {
return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
|| cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
}
return null;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Missing null/length check for cropBox will cause NullPointerException.

The method guards against a null or short rectangle array but performs no such check on cropBox. Per the PDPage.getCropBox() implementation (lines 112-119), when there is no /CropBox entry it falls back to getMediaBox(), which can return null. Accessing cropBox[0]cropBox[3] on a null reference will throw an NPE.

🐛 Proposed fix to add null/length guard for cropBox
     public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
         double[] cropBox = page.getCropBox();
         double[] rectangle = annotation.getRect();
-        if (rectangle != null && rectangle.length >= 4) {
+        if (cropBox != null && cropBox.length >= 4 && rectangle != null && rectangle.length >= 4) {
             return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
                     || cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
         }
         return null;
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
double[] cropBox = page.getCropBox();
double[] rectangle = annotation.getRect();
if (rectangle != null && rectangle.length >= 4) {
return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
|| cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
}
return null;
}
public static Boolean isOutsideCropBox(PDPage page, PDAnnotation annotation) {
double[] cropBox = page.getCropBox();
double[] rectangle = annotation.getRect();
if (cropBox != null && cropBox.length >= 4 && rectangle != null && rectangle.length >= 4) {
return cropBox[1] >= rectangle[3] || cropBox[0] >= rectangle[2]
|| cropBox[3] <= rectangle[1] || cropBox[2] <= rectangle[0];
}
return null;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/org/verapdf/pd/PDAnnotation.java` around lines 284 - 292, The
method PDAnnotation.isOutsideCropBox currently checks rectangle for null/length
but not cropBox; add a null and length guard for the cropBox returned by
PDPage.getCropBox() (similar to rectangle) before indexing cropBox[0]..[3], and
return null if cropBox is null or has length < 4; update the conditional that
computes the boolean to only run when both cropBox and rectangle are non-null
and length >= 4 (method names: isOutsideCropBox, PDPage.getCropBox, local
variables: cropBox, rectangle).

@MaximPlusov MaximPlusov merged commit b1aa399 into integration Apr 2, 2026
9 checks passed
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.

2 participants