Skip to content

Implement Java version of COBOL merge_sort_test.cbl#1

Open
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/MBA-18-1749759168
Open

Implement Java version of COBOL merge_sort_test.cbl#1
devin-ai-integration[bot] wants to merge 1 commit intomainfrom
devin/MBA-18-1749759168

Conversation

@devin-ai-integration
Copy link
Copy Markdown

@devin-ai-integration devin-ai-integration Bot commented Jun 12, 2025

PR Description

This pull request implements the Java version of the COBOL program merge_sort_test.cbl. The implementation includes the following classes:

  • CustomerRecord: Represents the customer data structure with exact field sizes.
  • FileReader and FileWriter: Handle fixed-width record I/O matching COBOL's behavior.
  • MergeSortProcessor: Implements the merge and sort operations.

The program workflow includes:

  • Generating test data into two input files (test-file-1.txt and test-file-2.txt).
  • Merging files on ascending customerID into merge-output.txt.
  • Sorting merged results on descending contractID into sorted-contract-id.txt.

Ticket ID: MBA-18

Link to Devin run: https://app.devin.ai/sessions/c7c6f573566a4418bc9b3ec459ee7d26

Requested by: Shawn Azman (shawn@cognition.ai)


Open with Devin

Co-Authored-By: Shawn Azman <shawn.d.azman@gmail.com>
@devin-ai-integration
Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Copy Markdown
Author

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 3 additional findings in Devin Review.

Open in Devin Review

Comment thread src/FileWriter.java
Comment on lines +17 to +22
String line = String.format("%-5s%-50s%-50s%-5s%-25s",
record.getCustomerID(),
record.getLastName(),
record.getFirstName(),
record.getContractID(),
record.getComment());
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🔴 String.format does not enforce maximum field width, breaking round-trip with FileReader

In FileWriter.java:17, the format string "%-5s%-50s%-50s%-5s%-25s" uses minimum-width specifiers but does not enforce maximum widths. In Java, %-5s means "left-justify with minimum width 5" — if a string is longer than 5 characters, it will NOT be truncated. This means if any field value exceeds its designated column width (e.g., a customerID longer than 5 chars), the total line length will exceed 135 characters, and FileReader.java:20-24 will parse the fields at wrong positions, silently producing corrupt CustomerRecord objects. The fix is to use precision in the format specifiers: "%-5.5s%-50.50s%-50.50s%-5.5s%-25.25s".

Suggested change
String line = String.format("%-5s%-50s%-50s%-5s%-25s",
record.getCustomerID(),
record.getLastName(),
record.getFirstName(),
record.getContractID(),
record.getComment());
String line = String.format("%-5.5s%-50.50s%-50.50s%-5.5s%-25.25s",
record.getCustomerID(),
record.getLastName(),
record.getFirstName(),
record.getContractID(),
record.getComment());
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@devin-ai-integration
Copy link
Copy Markdown
Author

❌ Cannot revive Devin session - the session is too old. Please start a new session instead.

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.

0 participants