Skip to content

Commit

Permalink
Fix Avro parsing due to change apache/avro#2642 in Avro 1.12.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pvillard31 committed Oct 2, 2024
1 parent 505057d commit 6c2c9d3
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.nifi.schemaregistry.services;

import org.apache.avro.NameValidator;
import org.apache.avro.Schema;
import org.apache.nifi.annotation.behavior.DynamicProperty;
import org.apache.nifi.annotation.documentation.CapabilityDescription;
Expand Down Expand Up @@ -87,7 +88,7 @@ public void onPropertyModified(final PropertyDescriptor descriptor, final String
} else {
try {
// Use a non-strict parser here, a strict parse can be done (if specified) in customValidate().
final Schema avroSchema = new Schema.Parser().setValidate(false).parse(newValue);
final Schema avroSchema = new Schema.Parser(NameValidator.NO_VALIDATION).parse(newValue);
final SchemaIdentifier schemaId = SchemaIdentifier.builder().name(descriptor.getName()).build();
final RecordSchema recordSchema = AvroTypeUtil.createSchema(avroSchema, newValue, schemaId);
recordSchemas.put(descriptor.getName(), recordSchema);
Expand All @@ -109,7 +110,7 @@ protected Collection<ValidationResult> customValidate(ValidationContext validati
String input = entry.getValue();

try {
final Schema avroSchema = new Schema.Parser().setValidate(strict).parse(input);
final Schema avroSchema = new Schema.Parser(strict ? NameValidator.STRICT_VALIDATOR : NameValidator.UTF_VALIDATOR).parse(input);
AvroTypeUtil.createSchema(avroSchema, input, SchemaIdentifier.EMPTY);
} catch (final Exception e) {
results.add(new ValidationResult.Builder()
Expand Down

0 comments on commit 6c2c9d3

Please sign in to comment.