Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent IOB when printing topics with a key/value with an empty string #7162

Merged
merged 2 commits into from
Mar 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,15 @@ public List<String> format(final Iterable<ConsumerRecord<Bytes, Bytes>> records)

final List<String> formatted = formatRecords(records);

final boolean sameKeyFormatChanged = activeKeyFormat
.equals(keyDeserializers.getPossibleFormats().get(0));

final boolean sameValueFormatChanged = activeValueFormat
.equals(valueDeserializers.getPossibleFormats().get(0));
final boolean sameKeyFormatChanged = keyDeserializers
.getPossibleFormats()
.stream()
.anyMatch(activeKeyFormat::equals);

final boolean sameValueFormatChanged = valueDeserializers
.getPossibleFormats()
.stream()
.anyMatch(activeValueFormat::equals);

if (sameKeyFormatChanged && sameValueFormatChanged) {
return formatted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1274,14 +1274,16 @@ public void shouldReprocessBatchIfLikelyKeyFormatChanges() {
final Iterable<ConsumerRecord<Bytes, Bytes>> records = consumerRecords(
// Key that is same size as BIGINT / DOUBLE:
consumerRecord(Bytes.wrap("Die Hard".getBytes(UTF_8)), null),
consumerRecord(Bytes.wrap("Key that's clearly a string".getBytes(UTF_8)), null)
consumerRecord(Bytes.wrap("Key that's clearly a string".getBytes(UTF_8)), null),
consumerRecord(Bytes.wrap("".getBytes(UTF_8)), null)
);

// When:
final List<String> formatted = formatter.format(records);

// Then:
assertThat(formatted.get(0), containsString("Die Hard"));
assertThat(formatted.get(1), containsString("Key that's clearly a string"));
}

@Test
Expand All @@ -1290,14 +1292,16 @@ public void shouldReprocessBatchIfLikelyValueFormatChanges() {
final Iterable<ConsumerRecord<Bytes, Bytes>> records = consumerRecords(
// Value that is same size as BIGINT / DOUBLE:
consumerRecord(null, Bytes.wrap("Die Hard".getBytes(UTF_8))),
consumerRecord(null, Bytes.wrap("Key that's clearly a string".getBytes(UTF_8)))
consumerRecord(null, Bytes.wrap("Value that's clearly a string".getBytes(UTF_8))),
consumerRecord(null, Bytes.wrap("".getBytes(UTF_8)))
);

// When:
final List<String> formatted = formatter.format(records);

// Then:
assertThat(formatted.get(0), containsString("Die Hard"));
assertThat(formatted.get(1), containsString("Value that's clearly a string"));
}


Expand Down