Conversation
📝 WalkthroughWalkthroughAdded two public static Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
src/main/java/org/verapdf/pd/PDAnnotation.java (2)
286-286: Use the existinggetRect()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 forpageandannotationparameters.If either parameter is
null, the method will throw aNullPointerExceptionat the first access. Either add defensive null checks or document the non-null precondition with@paramJavadoc.🛡️ 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
📒 Files selected for processing (1)
src/main/java/org/verapdf/pd/PDAnnotation.java
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
src/main/java/org/verapdf/pd/PDAnnotation.java
| 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; | ||
| } |
There was a problem hiding this comment.
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.
| 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).
Summary by CodeRabbit