yihua commented on code in PR #19956:
URL: https://github.com/apache/hudi/pull/19956#discussion_r4019930651
##########
hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java:
##########
@@ -1761,11 +1761,27 @@ private static <T extends SpecificRecordBase> T
convertToSpecificRecord(Class<T>
}
}
+ /**
+ * Loads the generated class for a nested RECORD schema with {@code
Class.forName}, bypassing the
+ * {@code ClassSecurityValidator} check that Avro 1.12.2+ runs in {@code
ClassUtils.forName} (reached from
+ * {@link SpecificData#getClass(Schema)}), which rejects Hudi's generated
classes.
+ *
+ * <p>Only pass schemas taken from a compiled SCHEMA$, never a schema read
from storage, which is what the validation guards against.
+ */
+ private static Class<? extends SpecificRecordBase>
getSpecificRecordClass(Schema recordSchema, SpecificData specificData) {
+ String className = SpecificData.getClassName(recordSchema);
+ try {
+ return Class.forName(className, false,
specificData.getClassLoader()).asSubclass(SpecificRecordBase.class);
+ } catch (ClassNotFoundException e) {
+ throw new HoodieException("Failed to load SpecificRecord class " +
className + " for Avro schema " + recordSchema.getFullName(), e);
+ }
Review Comment:
Avro SpecificData has class cache inside so it's cached
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]