You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by GitBox <gi...@apache.org> on 2021/04/19 16:37:33 UTC

[GitHub] [kafka] rhauch commented on a change in pull request #9541: KAFKA-10675: Add schema name to ConnectSchema.validateValue() error message

rhauch commented on a change in pull request #9541:
URL: https://github.com/apache/kafka/pull/9541#discussion_r615975188



##########
File path: connect/api/src/main/java/org/apache/kafka/connect/data/ConnectSchema.java
##########
@@ -266,7 +267,7 @@ public static void validateValue(String name, Schema schema, Object value) {
     private static List<Class> expectedClassesFor(Schema schema) {
         List<Class> expectedClasses = LOGICAL_TYPE_CLASSES.get(schema.name());
         if (expectedClasses == null)
-            expectedClasses = SCHEMA_TYPE_CLASSES.get(schema.type());
+            expectedClasses = SCHEMA_TYPE_CLASSES.getOrDefault(schema.type(), Collections.emptyList());

Review comment:
       Strictly speaking, this shouldn't be necessary as `SCHEMA_TYPE_CLASSES` should have a `Schema` instance for all `Schema.Type` literals. And with `SchemaBuilder` a connector or converter cannot create a schema instance with a null `Schema.Type`. 
   
   However, it is possible to construct a `ConnectSchema` instance with a null `Type` reference (like what `FakeSchema` essentially does in the existing test), which of course without this change would result in this method returning a null list. 
   
   So +1 for this line change since it simplifies the error handling in the calling code.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org