Harden self-inclusive binary prefixes and add packager tests - #741
Merged
Conversation
Follow-ups to #740: - SelfInclusiveBinaryPrefixer.of(BinaryPrefixer) reuses the B/BB singletons and wraps any binary prefixer; maxLength() generalized to n-byte prefixes. - ISOBinaryFieldPackager selects the inclusive prefixer via instanceof rather than singleton identity, so any binary length prefix works, and throws ISOException on a non-binary prefix. - GenericPackagerParams.setGenericPackagerParams now declares throws ISOException, matching the packager-XML error convention; overriding implementations are unaffected (fewer checked exceptions). - Tests: inclusive="true" on an isofieldpackager with subfields (Visa field 126.18 shape, round-trip) and rejection on a non-binary-prefix field. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Follow-ups to #740 (self-inclusive binary length prefixes).
Robustness
SelfInclusiveBinaryPrefixer.of(BinaryPrefixer)— a factory that reuses theB/BBsingletons for the common one- and two-byte cases and wraps any other binary prefixer.maxLength()is generalized from the hard-coded 1-/2-byte cap to n-byte prefixes.ISOBinaryFieldPackager.setGenericPackagerParamsnow selects the inclusive prefixer viainstanceof BinaryPrefixer+ the factory, instead of comparing against theBinaryPrefixer.B/.BBsingleton instances. A field that installs a non-singletonnew BinaryPrefixer(n)now works instead of being wrongly rejected.Error handling
GenericPackagerParams.setGenericPackagerParamsnow declaresthrows ISOException, and the non-binary-prefix rejection throwsISOException(checked) rather than an uncheckedIllegalArgumentException. This matches the packager-XML error convention (GenericPackager.readFilesurfaces it asISOException). Existing overriding implementations are unaffected — an override may declare fewer checked exceptions.Tests
testInclusiveIsoFieldPackagerWithSubfields—inclusive="true"on anisofieldpackagerwhose value is a subfield packager (the Visa Base I field 126.18 shape: 1-byte self-inclusive length wrappingIFE_CHAR+IFB_BINARYsubfields), asserting the0x0Bprefix, the recovered subfields, and consumed length. This is the motivating real-world path, which Support self-inclusive binary prefixes #740 did not cover with a test.testInclusiveRejectsNonBinaryPrefix—inclusive="true"onIFB_BINARY(no binary length prefix) is rejected rather than silently ignored../gradlew :jpos:testpasses (Java 26.0.1-amzn).