Skip to content

Preserve empty attributes when parsing composite keys - #646

Open
RaphaelFakhri wants to merge 1 commit into
hyperledger:mainfrom
RaphaelFakhri:fix-composite-key-empty-attributes
Open

RaphaelFakhri wants to merge 1 commit into
hyperledger:mainfrom
RaphaelFakhri:fix-composite-key-empty-attributes

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

CompositeKey.parseCompositeKey(), used by ChaincodeStub.splitCompositeKey(), splits the key with String.split(delimiter, 0). That call discards trailing empty strings, so empty attributes at the end of a key are lost:

  • \u0000abc\u0000\u0000def\u0000\u0000\u0000 parses to the attributes ["", "def"] instead of ["", "def", "", ""], and toString() on the result no longer returns the original ledger key.
  • \u0000\u0000 (empty object type, no attributes) throws ArrayIndexOutOfBoundsException.

This change splits with a negative limit to keep empty segments and drops only the empty segment after the final delimiter. The behavior now matches the Go and Node shims. Keys without empty attributes parse as before.

Tests added in CompositeKeyTest cover empty middle and trailing attributes and an empty object type, including the round trip through toString().

Closes #645

CompositeKey.parseCompositeKey() split the key with String.split(delimiter, 0),
which discards trailing empty strings. Empty trailing attributes were lost, so
the parsed key no longer matched the original ledger key, and a composite key
with an empty object type and no attributes failed with an
ArrayIndexOutOfBoundsException. The Go and Node shims keep these attributes.

Signed-off-by: Raphael Fakhri <153192858+RaphaelFakhri@users.noreply.github.com>
@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner November 4, 2026 07:07
@sonarqubecloud

sonarqubecloud Bot commented Nov 4, 2026

Copy link
Copy Markdown

This branch has not been deployed

No deployments
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.

splitCompositeKey drops empty trailing attributes

1 participant