#845 Fix in place processing to retain bytes from start and end offsets or the original file when the processing strategy is 'InPlace'#849
Conversation
…s in-place using 'CobolProcessor'.
…s in-place using 'SparkCobolProcessor'.
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughThe PR extends in-place COBOL file processing to preserve unmodified file start- and end-offset boundary bytes. FSStream gains boundary tracking via a ChangesPreserve file start/end offset bytes in in-place COBOL processing
🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 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 |
JaCoCo code coverage report - 'cobol-parser'
|
JaCoCo code coverage report - 'spark-cobol'
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/stream/FSStream.scala (1)
53-66: ⚡ Quick winClarify the semantics of
getSkippedEndBytesor add defensive checks.The method closes the stream (line 63) when not at the effective end, which could cause silent failures if called prematurely. The else-branch semantics are unclear: should this method be called only when
byteIndex >= effectiveSize, or is the close a defensive cleanup?Consider either:
- Documenting that this method must only be called after reading all effective bytes, or
- Throwing an exception instead of silently closing when called prematurely.
♻️ Option: Add explicit precondition check
def getSkippedEndBytes: Array[Byte] = { - if (byteIndex >= effectiveSize && !isClosed) { + if (byteIndex < effectiveSize) { + throw new IllegalStateException(s"Cannot retrieve end bytes before reaching effective end (at $byteIndex of $effectiveSize)") + } + if (!isClosed) { val b = new Array[Byte](fileEndOffset.toInt) val actual = bytesStream.read(b, 0, fileEndOffset.toInt) if (actual <= 0) { Array.empty[Byte] } else { b.take(actual) } } else { - close() Array.empty[Byte] } }🤖 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 `@cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/stream/FSStream.scala` around lines 53 - 66, The getSkippedEndBytes method currently closes the stream and returns empty bytes when called before byteIndex >= effectiveSize, which can hide incorrect usage; update getSkippedEndBytes to enforce a clear precondition: check that byteIndex >= effectiveSize and if not, either throw an IllegalStateException with a descriptive message (e.g., referencing getSkippedEndBytes, byteIndex and effectiveSize) or document the method contract at its declaration so callers know it must be called only after reading all effective bytes; ensure the code references the existing symbols (getSkippedEndBytes, byteIndex, effectiveSize, close, bytesStream, fileEndOffset) so the precondition is implemented in place of silently closing the stream.
🤖 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
`@cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/stream/FSStream.scala`:
- Around line 38-51: Validate fileStartOffset/fileEndOffset before casting to
Int in getSkippedStartBytes and getSkippedEndBytes: check that each offset is
within 0 to Int.MaxValue and reject (e.g., throw IllegalArgumentException with a
clear message) if out of bounds to avoid silent overflow and huge array
allocation; only perform the toInt cast after this validation and then proceed
with array allocation and reads as before. Ensure the same guard (non-negative
and <= Int.MaxValue) is applied to both getSkippedStartBytes and
getSkippedEndBytes and include the offset value in the exception message for
debugging.
---
Nitpick comments:
In
`@cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/stream/FSStream.scala`:
- Around line 53-66: The getSkippedEndBytes method currently closes the stream
and returns empty bytes when called before byteIndex >= effectiveSize, which can
hide incorrect usage; update getSkippedEndBytes to enforce a clear precondition:
check that byteIndex >= effectiveSize and if not, either throw an
IllegalStateException with a descriptive message (e.g., referencing
getSkippedEndBytes, byteIndex and effectiveSize) or document the method contract
at its declaration so callers know it must be called only after reading all
effective bytes; ensure the code references the existing symbols
(getSkippedEndBytes, byteIndex, effectiveSize, close, bytesStream,
fileEndOffset) so the precondition is implemented in place of silently closing
the stream.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c89094d1-0b52-4fa4-a511-9611bbbcd248
📒 Files selected for processing (6)
cobol-parser/src/main/scala/za/co/absa/cobrix/cobol/processor/impl/CobolProcessorInPlace.scalacobol-parser/src/main/scala/za/co/absa/cobrix/cobol/reader/stream/FSStream.scalacobol-parser/src/test/scala/za/co/absa/cobrix/cobol/processor/CobolProcessorBuilderSuite.scalaspark-cobol/src/main/scala/za/co/absa/cobrix/spark/cobol/SparkCobolProcessor.scalaspark-cobol/src/main/scala/za/co/absa/cobrix/spark/cobol/source/streaming/FileStreamer.scalaspark-cobol/src/test/scala/za/co/absa/cobrix/spark/cobol/SparkCobolProcessorSuite.scala
💤 Files with no reviewable changes (1)
- spark-cobol/src/main/scala/za/co/absa/cobrix/spark/cobol/source/streaming/FileStreamer.scala
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
8234cee to
78b6660
Compare
Summary by CodeRabbit
Bug Fixes
Improvements
Tests