debasishg commented on a change in pull request #9565: [FLINK-12501] Use SpecificRecord.getSchema in AvroFactory URL: https://github.com/apache/flink/pull/9565#discussion_r319598469
########## File path: flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/typeutils/AvroFactory.java ########## @@ -94,7 +94,8 @@ static Schema parseSchemaString(@Nullable String schemaString) { @SuppressWarnings("OptionalUsedAsFieldOrParameterType") private static <T> AvroFactory<T> fromSpecific(Class<T> type, ClassLoader cl, Optional<Schema> previousSchema) { SpecificData specificData = new SpecificData(cl); - Schema newSchema = specificData.getSchema(type); + Optional<Schema> newSchemaOptional = tryExtractAvroSchema(type); + Schema newSchema = newSchemaOptional.orElse(specificData.getSchema(type)); Review comment: I faced a problem here which comes from the use of `Optional.orElse`. It's a known gotcha with `orElse`. Even though `newSchemaOptional` is non-empty, `orElse` will evaluate the argument passed as default. Hence it tries to evaluate `specificData.getSchema(type))` and fails with the earlier exception. The workaround is to change `orElse` to `orElseGet` and pass a lambda instead .. ```java Schema newSchema = newSchemaOptional.orElseGet(() -> specificData.getSchema(type)); ``` This fixes the problem and runs ok. There are a few other invocations of `orElse` in this class which you may want to change to `orElseGet` as well .. I cherrypicked your commit into the `release-1.9` branch and did a build which runs fine. Thanks for the help. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services