Skip to content
Open
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 @@ -23,6 +23,7 @@
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.Locale;
import org.apache.avro.LogicalTypes;
import org.apache.avro.Schema;
import org.apache.avro.io.BinaryDecoder;
Expand Down Expand Up @@ -73,9 +74,8 @@ public static <T> T decode(byte[] data) throws IOException {
byte header1 = dataInput.readByte();
Preconditions.checkState(
header0 == MAGIC_BYTES[0] && header1 == MAGIC_BYTES[1],
"Unrecognized header bytes: 0x%02X 0x%02X",
header0,
header1);
"%s",
String.format(Locale.ROOT, "Unrecognized header bytes: 0x%02X 0x%02X", header0, header1));

// Read avro schema
Schema avroSchema = new Schema.Parser().parse(dataInput.readUTF());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.iceberg.avro;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import java.io.IOException;
import java.util.List;
Expand All @@ -27,6 +28,7 @@
import org.apache.avro.generic.GenericData;
import org.apache.iceberg.data.DataTestBase;
import org.apache.iceberg.types.Type;
import org.junit.jupiter.api.Test;

public class TestAvroEncoderUtil extends DataTestBase {
@Override
Expand Down Expand Up @@ -68,4 +70,11 @@ protected void writeAndValidate(org.apache.iceberg.Schema schema) throws IOExcep
assertThat(record.toString()).isEqualTo(expectedRecord.toString());
}
}

@Test
public void decodeRejectsUnrecognizedHeaderBytes() {
assertThatThrownBy(() -> AvroEncoderUtil.decode(new byte[] {(byte) 0x10, (byte) 0x20}))
.isInstanceOf(IllegalStateException.class)
.hasMessage("Unrecognized header bytes: 0x10 0x20");
}
}
Loading