Add isEquivalentTo method to COSBase and COSObject - #712
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
🚧 Files skipped from review as they are similar to previous changes (13)
📝 WalkthroughWalkthroughThe change adds recursive equivalence checking across COS arrays, dictionaries, streams, wrappers, and scalar types. Numeric values compare through ChangesCOS equivalence
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant COSArray
participant COSDictionary
participant COSStream
participant COSBasePair
COSArray->>COSBasePair: Check and record compared pairs
COSArray->>COSDictionary: Compare nested COSBase values
COSDictionary->>COSBasePair: Check and record compared pairs
COSDictionary->>COSStream: Compare nested stream values
COSStream->>COSBasePair: Check and record compared pairs
COSStream->>COSDictionary: Compare decoded bytes and dictionary entries
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 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.
Actionable comments posted: 9
🧹 Nitpick comments (1)
src/main/java/org/verapdf/cos/COSDictionary.java (1)
302-311: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueStray/inaccurate comment.
// assume getKey returns a COSBase wrapperis confusing —getKeyreturns aCOSObject(the wrapper), and.get()on it yields theCOSBase. Looks like a leftover authoring note.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/main/java/org/verapdf/cos/COSDictionary.java` around lines 302 - 311, Remove the inaccurate authoring comment from getNonNullKeySet while preserving the existing getKey(key).get() value retrieval and null-filtering behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/verapdf/cos/COSBase.java`:
- Around line 145-147: Preserve the supplied cycle-detection state during
equivalent comparisons: update COSBase.isEquivalentTo(Object, List<COSBasePair>)
to dispatch recursive comparisons with the existing checkedObjects list, and
update both COSIndirect comparison paths at
src/main/java/org/verapdf/cos/COSIndirect.java lines 483-486 and 492-497 to pass
that same list when comparing indirect targets, including COSObject targets; do
not restart traversal through one-argument methods.
In `@src/main/java/org/verapdf/cos/COSDictionary.java`:
- Around line 313-335: Update both overloads of COSDictionary.isEquivalentTo,
including the recursive variant, to reject COSStream and any other COSDictionary
subclass before comparing entries; preserve COSObject unwrapping and allow only
exact COSDictionary instances through the dictionary comparison path.
In `@src/main/java/org/verapdf/cos/COSName.java`:
- Around line 95-107: Update COSName.isEquivalentTo to handle null ASAtom values
before calling getValue() or converting to bytes. Ensure two null values compare
as equivalent, a null versus non-null value returns false, and retain the
existing byte comparison for non-null values.
In `@src/main/java/org/verapdf/cos/COSObject.java`:
- Around line 497-505: Update COSObject.isEquivalentTo in
src/main/java/org/verapdf/cos/COSObject.java:497-505 to handle null base values
before delegating, preserving equivalent empty-wrapper behavior. Also update
COSIndirect.isEquivalentTo in
src/main/java/org/verapdf/cos/COSIndirect.java:487-494 to check getDirect() for
null or unresolved results before accessing base, and define equivalence
consistently without dereferencing null objects.
In `@src/main/java/org/verapdf/cos/COSReal.java`:
- Around line 49-52: Ensure non-finite values accepted by
COSReal.setValue(double) cannot reach BigDecimal conversion: update COSReal’s
set/setReal/construct paths to reject NaN and infinities, or explicitly handle
them in COSReal.getDecimalValue() before BigDecimal.valueOf(value). Also update
COSInteger.isEquivalentTo(...) to handle non-finite COSReal values without
invoking BigDecimal conversion; apply the changes in
src/main/java/org/verapdf/cos/COSReal.java lines 49-52 and
src/main/java/org/verapdf/cos/COSInteger.java lines 88-90.
In `@src/main/java/org/verapdf/cos/COSStream.java`:
- Around line 320-329: Update the decoded-stream comparison block in
COSStream.equals to manage both getData(FilterFlags.DECODE) results with
try-with-resources, ensuring thisDecoded and thatDecoded are closed on success
and IOException while preserving the existing equalsDecodedStreams and failure
behavior.
- Around line 320-329: Update the decoded-stream comparison block in
COSStream.equals(Object, List) to guard against either this.stream or
that.stream being null before calling getData(). Return false for the
null-stream case, matching the existing stream checks in equals(Object, List),
while preserving the current decoded comparison and IOException handling for
non-null streams.
In `@src/main/java/org/verapdf/cos/COSString.java`:
- Around line 437-448: Update COSString.isEquivalentTo(Object) to unwrap a
COSObject argument before checking for COSString and comparing canonical bytes,
matching the established behavior of COSStream, COSDictionary, and COSArray.
Preserve identity handling and return false for unsupported underlying types.
- Around line 383-398: Fix octal escape handling in the parsing loop around the
octal accumulation logic so the outer iteration advances past the final consumed
octal digit before continue, preventing it from being emitted again as a
literal. Preserve correct one- to three-digit octal decoding, and add unit
coverage for escapes such as \101 and \7 through isEquivalentTo or
getCanonicalBytes.
---
Nitpick comments:
In `@src/main/java/org/verapdf/cos/COSDictionary.java`:
- Around line 302-311: Remove the inaccurate authoring comment from
getNonNullKeySet while preserving the existing getKey(key).get() value retrieval
and null-filtering behavior.
🪄 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 Plus
Run ID: 168acea3-5e14-4e08-ab69-3fe3b6814d78
📒 Files selected for processing (13)
src/main/java/org/verapdf/cos/COSArray.javasrc/main/java/org/verapdf/cos/COSBase.javasrc/main/java/org/verapdf/cos/COSBoolean.javasrc/main/java/org/verapdf/cos/COSDictionary.javasrc/main/java/org/verapdf/cos/COSIndirect.javasrc/main/java/org/verapdf/cos/COSInteger.javasrc/main/java/org/verapdf/cos/COSName.javasrc/main/java/org/verapdf/cos/COSNull.javasrc/main/java/org/verapdf/cos/COSNumber.javasrc/main/java/org/verapdf/cos/COSObject.javasrc/main/java/org/verapdf/cos/COSReal.javasrc/main/java/org/verapdf/cos/COSStream.javasrc/main/java/org/verapdf/cos/COSString.java
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/main/java/org/verapdf/cos/COSInteger.java`:
- Around line 81-85: Update isEquivalentTo in
src/main/java/org/verapdf/cos/COSInteger.java lines 81-85, COSBoolean.java lines
75-79, COSName.java lines 96-100, and COSString.java lines 369-373 to return
false when the operand is null before calling isIndirect(); also guard the
dereferenced result so unresolved indirect operands return false instead of
throwing.
🪄 Autofix
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 Plus
Run ID: e31f0423-195f-4a18-88d9-dd00fddb2270
📒 Files selected for processing (12)
src/main/java/org/verapdf/cos/COSArray.javasrc/main/java/org/verapdf/cos/COSBase.javasrc/main/java/org/verapdf/cos/COSBoolean.javasrc/main/java/org/verapdf/cos/COSDictionary.javasrc/main/java/org/verapdf/cos/COSIndirect.javasrc/main/java/org/verapdf/cos/COSInteger.javasrc/main/java/org/verapdf/cos/COSName.javasrc/main/java/org/verapdf/cos/COSNull.javasrc/main/java/org/verapdf/cos/COSObject.javasrc/main/java/org/verapdf/cos/COSReal.javasrc/main/java/org/verapdf/cos/COSStream.javasrc/main/java/org/verapdf/cos/COSString.java
🚧 Files skipped from review as they are similar to previous changes (3)
- src/main/java/org/verapdf/cos/COSStream.java
- src/main/java/org/verapdf/cos/COSNull.java
- src/main/java/org/verapdf/cos/COSReal.java
Add support for object comparison from ISO32000-2:2020 Annex J
3d16ada to
01f493e
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Add support for object comparison from ISO32000-2:2020 Annex J
Summary by CodeRabbit