mirror of https://github.com/apache/kafka.git
KAFKA-8150: Fix bugs in handling null arrays in generated RPC code (#6489)
ToString functions must not get a NullPointException. read() functions must properly translate a negative array length to a null field. Reviewers: Manikumar Reddy <manikumar.reddy@gmail.com>
This commit is contained in:
parent
e4cad35312
commit
e0d028bf6c
|
@ -38,7 +38,6 @@ import org.apache.kafka.common.utils.Utils;
|
||||||
import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTopic;
|
import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTopic;
|
||||||
import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTopicSet;
|
import org.apache.kafka.common.message.AddPartitionsToTxnRequestData.AddPartitionsToTxnTopicSet;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.rules.Timeout;
|
import org.junit.rules.Timeout;
|
||||||
|
@ -47,7 +46,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public final class MessageTest {
|
public final class MessageTest {
|
||||||
@Rule
|
@Rule
|
||||||
final public Timeout globalTimeout = Timeout.millis(120000);
|
final public Timeout globalTimeout = Timeout.millis(120000);
|
||||||
|
@ -87,6 +85,11 @@ public final class MessageTest {
|
||||||
setHostFilter(null).
|
setHostFilter(null).
|
||||||
setOperation((byte) 0).
|
setOperation((byte) 0).
|
||||||
setPermissionType((byte) 0), (short) 0);
|
setPermissionType((byte) 0), (short) 0);
|
||||||
|
testMessageRoundTrips(new MetadataRequestData().
|
||||||
|
setTopics(null).
|
||||||
|
setAllowAutoTopicCreation(false).
|
||||||
|
setIncludeClusterAuthorizedOperations(false).
|
||||||
|
setIncludeTopicAuthorizedOperations(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testMessageRoundTrips(Message message) throws Exception {
|
private void testMessageRoundTrips(Message message) throws Exception {
|
||||||
|
|
|
@ -416,9 +416,8 @@ public final class MessageDataGenerator {
|
||||||
buffer.printf("int arrayLength = readable.readInt();%n");
|
buffer.printf("int arrayLength = readable.readInt();%n");
|
||||||
buffer.printf("if (arrayLength < 0) {%n");
|
buffer.printf("if (arrayLength < 0) {%n");
|
||||||
buffer.incrementIndent();
|
buffer.incrementIndent();
|
||||||
buffer.printf("this.%s.clear(%s);%n",
|
buffer.printf("this.%s = null;%n",
|
||||||
field.camelCaseName(),
|
field.camelCaseName());
|
||||||
hasKeys ? "0" : "");
|
|
||||||
buffer.decrementIndent();
|
buffer.decrementIndent();
|
||||||
buffer.printf("} else {%n");
|
buffer.printf("} else {%n");
|
||||||
buffer.incrementIndent();
|
buffer.incrementIndent();
|
||||||
|
@ -1069,8 +1068,14 @@ public final class MessageDataGenerator {
|
||||||
prefix, field.camelCaseName(), field.camelCaseName());
|
prefix, field.camelCaseName(), field.camelCaseName());
|
||||||
} else if (field.type().isArray()) {
|
} else if (field.type().isArray()) {
|
||||||
headerGenerator.addImport(MessageGenerator.MESSAGE_UTIL_CLASS);
|
headerGenerator.addImport(MessageGenerator.MESSAGE_UTIL_CLASS);
|
||||||
buffer.printf("+ \"%s%s=\" + MessageUtil.deepToString(%s.iterator())%n",
|
if (field.nullableVersions().empty()) {
|
||||||
prefix, field.camelCaseName(), field.camelCaseName());
|
buffer.printf("+ \"%s%s=\" + MessageUtil.deepToString(%s.iterator())%n",
|
||||||
|
prefix, field.camelCaseName(), field.camelCaseName());
|
||||||
|
} else {
|
||||||
|
buffer.printf("+ \"%s%s=\" + ((%s == null) ? \"null\" : " +
|
||||||
|
"MessageUtil.deepToString(%s.iterator()))%n",
|
||||||
|
prefix, field.camelCaseName(), field.camelCaseName(), field.camelCaseName());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unsupported field type " + field.type());
|
throw new RuntimeException("Unsupported field type " + field.type());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue