kafka-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ewe...@apache.org
Subject kafka git commit: KAFKA-3690: Avoid to pass null to UnmodifiableMap
Date Wed, 11 May 2016 20:06:36 GMT
Repository: kafka
Updated Branches:
  refs/heads/trunk 697811551 -> bd8681cdd


KAFKA-3690: Avoid to pass null to UnmodifiableMap

Author: Liquan Pei <liquanpei@gmail.com>

Reviewers: Jason Gustafson <jason@confluent.io>, Ismael Juma <ismael@juma.me.uk>,
Ewen Cheslack-Postava <ewen@confluent.io>

Closes #1360 from Ishiihara/avoid-to-pass-null


Project: http://git-wip-us.apache.org/repos/asf/kafka/repo
Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/bd8681cd
Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/bd8681cd
Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/bd8681cd

Branch: refs/heads/trunk
Commit: bd8681cdd51d2878ea917941abe335f68a373716
Parents: 6978115
Author: Liquan Pei <liquanpei@gmail.com>
Authored: Wed May 11 13:06:20 2016 -0700
Committer: Ewen Cheslack-Postava <me@ewencp.org>
Committed: Wed May 11 13:06:20 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/kafka/connect/data/SchemaBuilder.java   | 2 +-
 .../org/apache/kafka/connect/data/SchemaBuilderTest.java    | 9 ++++++++-
 .../kafka/connect/storage/KafkaConfigBackingStore.java      | 2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kafka/blob/bd8681cd/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
----------------------------------------------------------------------
diff --git a/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java b/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
index 3d2f5cc..32045f9 100644
--- a/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
+++ b/connect/api/src/main/java/org/apache/kafka/connect/data/SchemaBuilder.java
@@ -181,7 +181,7 @@ public class SchemaBuilder implements Schema {
 
     @Override
     public Map<String, String> parameters() {
-        return Collections.unmodifiableMap(parameters);
+        return parameters == null ? null : Collections.unmodifiableMap(parameters);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/kafka/blob/bd8681cd/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaBuilderTest.java
----------------------------------------------------------------------
diff --git a/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaBuilderTest.java
b/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaBuilderTest.java
index 62020f3..fdbaa0a 100644
--- a/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaBuilderTest.java
+++ b/connect/api/src/test/java/org/apache/kafka/connect/data/SchemaBuilderTest.java
@@ -252,7 +252,14 @@ public class SchemaBuilderTest {
 
     @Test
     public void testMapBuilder() {
-        Schema schema = SchemaBuilder.map(Schema.INT8_SCHEMA, Schema.INT8_SCHEMA).build();
+        // SchemaBuilder should also pass the check
+        Schema schema = SchemaBuilder.map(Schema.INT8_SCHEMA, Schema.INT8_SCHEMA);
+        assertTypeAndDefault(schema, Schema.Type.MAP, false, null);
+        assertEquals(schema.keySchema(), Schema.INT8_SCHEMA);
+        assertEquals(schema.valueSchema(), Schema.INT8_SCHEMA);
+        assertNoMetadata(schema);
+
+        schema = SchemaBuilder.map(Schema.INT8_SCHEMA, Schema.INT8_SCHEMA).build();
         assertTypeAndDefault(schema, Schema.Type.MAP, false, null);
         assertEquals(schema.keySchema(), Schema.INT8_SCHEMA);
         assertEquals(schema.valueSchema(), Schema.INT8_SCHEMA);

http://git-wip-us.apache.org/repos/asf/kafka/blob/bd8681cd/connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaConfigBackingStore.java
----------------------------------------------------------------------
diff --git a/connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaConfigBackingStore.java
b/connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaConfigBackingStore.java
index 9a93a4e..af8efee 100644
--- a/connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaConfigBackingStore.java
+++ b/connect/runtime/src/main/java/org/apache/kafka/connect/storage/KafkaConfigBackingStore.java
@@ -179,7 +179,7 @@ public class KafkaConfigBackingStore implements ConfigBackingStore {
     // converter/serializer changes causing keys to change. We need to absolutely ensure
that the keys remain precisely
     // the same.
     public static final Schema CONNECTOR_CONFIGURATION_V0 = SchemaBuilder.struct()
-            .field("properties", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA))
+            .field("properties", SchemaBuilder.map(Schema.STRING_SCHEMA, Schema.OPTIONAL_STRING_SCHEMA).build())
             .build();
     public static final Schema TASK_CONFIGURATION_V0 = CONNECTOR_CONFIGURATION_V0;
     public static final Schema CONNECTOR_TASKS_COMMIT_V0 = SchemaBuilder.struct()


Mime
View raw message