[ 
https://issues.apache.org/jira/browse/GOBBLIN-987?focusedWorklogId=351185&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-351185
 ]

ASF GitHub Bot logged work on GOBBLIN-987:
------------------------------------------

                Author: ASF GitHub Bot
            Created on: 29/Nov/19 00:21
            Start Date: 29/Nov/19 00:21
    Worklog Time Spent: 10m 
      Work Description: zxcware commented on pull request #2833: [GOBBLIN-987] 
Reject unrecognized Enum symbols in JsonRecordAvroSchemaToAvroConverter
URL: https://github.com/apache/incubator-gobblin/pull/2833#discussion_r351947678
 
 

 ##########
 File path: 
gobblin-core/src/main/java/org/apache/gobblin/converter/avro/JsonElementConversionWithAvroSchemaFactory.java
 ##########
 @@ -165,7 +166,10 @@ public EnumConverter(String fieldName, boolean nullable, 
String sourceType, Sche
 
     @Override
     Object convertField(JsonElement value) {
-      return new GenericData.EnumSymbol(this.schema, value.getAsString());
+      String valueString = value.getAsString();
+      Validate.isTrue(this.enumSet.contains(valueString),
 
 Review comment:
   most of our check is done with guava `Preconditions`. Replace 
`Validate.isTrue` with `Preconditions` to be consistent and avoid introducing a 
new dependency?
 
----------------------------------------------------------------
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:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 351185)
    Time Spent: 0.5h  (was: 20m)

> JsonRecordAvroSchemaToAvroConverter does not reject unrecognized Enum symbols
> -----------------------------------------------------------------------------
>
>                 Key: GOBBLIN-987
>                 URL: https://issues.apache.org/jira/browse/GOBBLIN-987
>             Project: Apache Gobblin
>          Issue Type: Bug
>            Reporter: Ahmed Abdul Hamid
>            Priority: Major
>         Attachments: invalid-enum-unit-test.patch
>
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Here is a failing unit test that demonstrates the issue we encounter when we 
> attempt to encode the records produced by 
> {{JsonRecordAvroSchemaToAvroConverter}} with unrecognized Enum symbols: 
> [^invalid-enum-unit-test.patch]
> Here's how to apply the patch and run the test:
> {code:bash}
> $ git apply invalid-enum-unit-test.patch$ 
> $ ./gradlew :gobblin-core:test --tests *testEnumConversion*  {code}
> Here's the output:
> {code:java}
> java.lang.NullPointerException: null of string in field fieldToIgnore of 
> org.apache.gobblin.test.TestRecord
>       at 
> org.apache.avro.generic.GenericDatumWriter.npe(GenericDatumWriter.java:132)
>       at 
> org.apache.avro.generic.GenericDatumWriter.writeWithoutConversion(GenericDatumWriter.java:126)
>       at 
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:73)
>       at 
> org.apache.avro.generic.GenericDatumWriter.write(GenericDatumWriter.java:60)
>       at 
> org.apache.gobblin.converter.avro.JsonRecordAvroSchemaToAvroConverterTest.testEnumConversion(JsonRecordAvroSchemaToAvroConverterTest.java:82)
>  {code}
> The root cause of the issue is that {{JsonRecordAvroSchemaToAvroConverter}} 
> allows unrecognized Enum symbols not declared in the specified Avro schema.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to