Rajeev-01 commented on code in PR #19596:
URL: https://github.com/apache/hudi/pull/19596#discussion_r3774746661


##########
hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java:
##########
@@ -124,6 +129,49 @@ public class HoodieAvroUtils {
 
   private static final Properties PROPERTIES = new Properties();
 
+  private static final Logger LOG = 
LoggerFactory.getLogger(HoodieAvroUtils.class);
+
+  /**
+   * Resolves the Avro library version, preferring Maven's generated 
pom.properties over
+   * {@link Package#getImplementationVersion()}. The latter comes from 
whatever manifest happens to
+   * seal the package, which is only avro's own manifest when avro ships as a 
standalone jar. But once
+   * its classes get merged or relocated into a shaded/fat jar, that lookup 
silently returns the
+   * assembling jar's version instead of avro's or nothing at all. So better 
to resolve with pom.properties
+   * followed by manifest version.
+   */
+  private static String resolveAvroVersion() {
+    final String path = "META-INF/maven/org.apache.avro/avro/pom.properties";
+    try {
+      URL schemaClassUrl = Schema.class.getResource("Schema.class");
+      String schemaArchive = schemaClassUrl == null ? null : 
archiveOf(schemaClassUrl);
+      Enumeration<URL> candidates = 
Schema.class.getClassLoader().getResources(path);
+      while (candidates.hasMoreElements()) {
+        URL candidate = candidates.nextElement();
+        // only use the pom.properties that ships in the same archive as the 
loaded Schema class
+        if (schemaArchive != null && 
!schemaArchive.equals(archiveOf(candidate))) {
+          continue;
+        }
+        Properties avroProperties = new Properties();
+        try (InputStream in = candidate.openStream()) {
+          avroProperties.load(in);
+        }
+        String version = avroProperties.getProperty("version");
+        if (version != null) {
+          return version;
+        }
+      }
+    } catch (Exception e) {
+      LOG.warn("Failed to resolve the avro version from {}, falling back to 
the jar manifest", path, e);

Review Comment:
   Removed the Logger and using lombok for logging



-- 
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]

Reply via email to