Skip to content

Commit

Permalink
KAFKA-3690: Avoid to pass null to UnmodifiableMap
Browse files Browse the repository at this point in the history
Author: Liquan Pei <[email protected]>

Reviewers: Jason Gustafson <[email protected]>, Ismael Juma <[email protected]>, Ewen Cheslack-Postava <[email protected]>

Closes apache#1360 from Ishiihara/avoid-to-pass-null
  • Loading branch information
Ishiihara authored and ewencp committed May 11, 2016
1 parent 6978115 commit bd8681c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public SchemaBuilder doc(String doc) {

@Override
public Map<String, String> parameters() {
return Collections.unmodifiableMap(parameters);
return parameters == null ? null : Collections.unmodifiableMap(parameters);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,14 @@ public void testArrayBuilderInvalidDefault() {

@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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static String COMMIT_TASKS_KEY(String connectorName) {
// 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()
Expand Down

0 comments on commit bd8681c

Please sign in to comment.