Skip to content

Harden self-inclusive binary prefixes and add packager tests - #741

Merged
ar merged 1 commit into
mainfrom
inclusive-prefixer-followups
Jul 17, 2026
Merged

Harden self-inclusive binary prefixes and add packager tests#741
ar merged 1 commit into
mainfrom
inclusive-prefixer-followups

Conversation

@ar

@ar ar commented Jul 17, 2026

Copy link
Copy Markdown
Member

Follow-ups to #740 (self-inclusive binary length prefixes).

Robustness

  • SelfInclusiveBinaryPrefixer.of(BinaryPrefixer) — a factory that reuses the B/BB singletons 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.setGenericPackagerParams now selects the inclusive prefixer via instanceof BinaryPrefixer + the factory, instead of comparing against the BinaryPrefixer.B/.BB singleton instances. A field that installs a non-singleton new BinaryPrefixer(n) now works instead of being wrongly rejected.

Error handling

  • GenericPackagerParams.setGenericPackagerParams now declares throws ISOException, and the non-binary-prefix rejection throws ISOException (checked) rather than an unchecked IllegalArgumentException. This matches the packager-XML error convention (GenericPackager.readFile surfaces it as ISOException). Existing overriding implementations are unaffected — an override may declare fewer checked exceptions.

Tests

  • testInclusiveIsoFieldPackagerWithSubfieldsinclusive="true" on an isofieldpackager whose value is a subfield packager (the Visa Base I field 126.18 shape: 1-byte self-inclusive length wrapping IFE_CHAR + IFB_BINARY subfields), asserting the 0x0B prefix, 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.
  • testInclusiveRejectsNonBinaryPrefixinclusive="true" on IFB_BINARY (no binary length prefix) is rejected rather than silently ignored.

./gradlew :jpos:test passes (Java 26.0.1-amzn).

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>
@ar
ar merged commit 0c4a606 into main Jul 17, 2026
1 check passed
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.

1 participant