Repository navigation
Fix #3986: compare alphanumerics as the mainframe does (CobolCompare) - #4036
Merged
Merged
Conversation
EBCDIC orders lower case before upper and letters before digits; Java's
String.compareTo orders digits first, so a ported `IF CUST-ID > 'A'` took the
other branch for '1001'. COBOL also pads the shorter operand with spaces
('AB' = 'AB '), which String.equals denies.
- util/CobolCompare, generated into every project: compare / eq / gt / ge /
lt / le by the data.code_page bytes, the shorter operand space-padded;
highValues(n) / lowValues(n); a null is spaces, an unencodable character
throws.
- A porting rule in every ticket: alphanumeric relation conditions only
through CobolCompare, numeric ones through BigDecimal.compareTo, and a
PROGRAM COLLATING SEQUENCE flagged in a TODO.
- A ticket rule when culture.key_collation is not ebcdic: browses and
CobolCompare can then order keys differently.
- The port runner shows the agent CobolCompare with the other runtimes.
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…st key_collation Every excerpt's generated project gains util/CobolCompare.java and its guardrail baseline entry (+1 file, +1 class); nothing else moved. key_collation, like decimal_point, is a Culture dataclass field that target_as_dict writes with vars(), which the dead-key walker cannot trace. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Contributor
The six pinned corpora's generated projects gain util/CobolCompare.java and its guardrail baseline entry (+1 file, +1 class); nothing else moved. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #3986. Follow-up: #4035.
Problem
EBCDIC sorts lower case before upper case and letters before digits (
a0x81 <A0xC1 <00xF0). Java'sString.compareTosorts digits first, so a portedIF CUST-ID > 'A'takes the opposite branch for'1001'. COBOL also pads the shorter operand with spaces ('AB' = 'AB '), whichString.equalsdenies.The generator never translates COBOL conditions (the AI porter writes that logic from the port ticket), so the fix is a runtime class for the porter to call, plus a rule that requires it.
Changes
util/CobolCompare, generated into every project (cobol_to_java_compare_forge.py, written by the controller). It is not tied to VSAM stores the wayCobolRecordsis.compare,eq,gt,ge,lt,lecompare the bytes in thedata.code_page(IBM037 by default), with the shorter operand padded with that code page's space.highValues(n)/lowValues(n)give HIGH-VALUES and LOW-VALUES.?.CobolCompare, nevercompareToorequals. Numeric comparisons stayBigDecimal.compareTo. A program that declaresPROGRAM COLLATING SEQUENCEhas to be flagged with a TODO.collation_rules: whenculture.key_collationisn'tebcdic, the ticket says that repository browses andCobolComparecan order keys differently, and that such spots should be flagged rather than "fixed".CobolCompareitself always follows the code page, as the program did.port_runner: the agent is shownutil/CobolCompare.javaalong with the other runtime classes.Snapshot bless
refraction_snapshot.py update(the excerpts) andupdate --corpus <each>(the 6 full pinned corpora): each generated project gainsutil/CobolCompare.javaand its guardrail-baseline entry, so the audit reads "+1 file, +1 class". Nothing else moved.dead_key_audit.py: allowlistkey_collation. Likedecimal_point(#3984), it's aCulturedataclass field thattarget_as_dictwrites withvars(), which the dead-key walker can't trace.Verification
test_cobol_compare.py: the Java test compiles and runsCobolCompareon 8 cases where EBCDIC order differs from Java's, plus padding, null, HIGH-/LOW-VALUES and an unencodable character. It skips withoutjavac; I ran it locally with JDK 21's compiler module.tests/cobol_mainframe+tests/cics_crucible: all pass after the bless. Before the bless, the only 6 failures were the snapshot diffs above.ruff formatclean.Not in this PR (#4035)
This PR makes the correct comparison available and requires it. It doesn't yet check that the porter used it. #4035 covers that:
collationviolation forcompareTo/equalson String fields;🤖 Generated with Claude Code