Skip to content
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 @@ -49,6 +49,7 @@
import org.apache.kafka.common.protocol.ByteBufferAccessor;
import org.apache.kafka.common.protocol.Errors;
import org.apache.kafka.common.protocol.Message;
import org.apache.kafka.common.protocol.MessageUtil;
import org.apache.kafka.common.protocol.ObjectSerializationCache;
import org.apache.kafka.common.protocol.types.RawTaggedField;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -749,6 +750,13 @@ public void testProduceResponseVersions() throws Exception {
}
}

@Test
public void defaultValueShouldBeWritable() {
for (short version = SimpleExampleMessageData.LOWEST_SUPPORTED_VERSION; version <= SimpleExampleMessageData.HIGHEST_SUPPORTED_VERSION; ++version) {
MessageUtil.toByteBuffer(new SimpleExampleMessageData(), version);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails without the change in this PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails without the change in this PR?

yep. The generated code is shown below.

            if (this.taggedUuid != Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A")) {
                throw new UnsupportedVersionException("Attempted to write a non-default taggedUuid at version " + _version);
            }

}
}

@Test
public void testSimpleMessage() throws Exception {
final SimpleExampleMessageData message = new SimpleExampleMessageData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ void generateNonDefaultValueCheck(HeaderGenerator headerGenerator,
fieldPrefix, camelCaseName(), fieldPrefix, camelCaseName());
}
}
} else if (type().isString() || type().isStruct()) {
} else if (type().isString() || type().isStruct() || type() instanceof FieldType.UUIDFieldType) {
if (fieldDefault.equals("null")) {
buffer.printf("if (%s%s != null) {%n", fieldPrefix, camelCaseName());
} else if (nullableVersions.empty()) {
Expand Down