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


##########
hudi-common/src/main/java/org/apache/hudi/common/avro/HoodieAvroUtils.java:
##########
@@ -124,6 +125,29 @@ public class HoodieAvroUtils {
 
   private static final Properties PROPERTIES = new Properties();
 
+  /**
+   * Resolves the Avro library version, preferring Maven's generated 
pom.properties over
+   * {@link Package#getImplementationVersion()}. The latter reads the jar 
manifest, which is
+   * present for a standalone avro-*.jar but is usually dropped for the avro 
package once its
+   * classes are merged into a shaded/fat jar.
+   */
+  private static String resolveAvroVersion() {
+    String avroPomPropertiesPath = 
"META-INF/maven/org.apache.avro/avro/pom.properties";
+    try (InputStream inputStream = 
Schema.class.getClassLoader().getResourceAsStream(avroPomPropertiesPath)) {
+      if (inputStream != null) {
+        Properties avroProperties = new Properties();
+        avroProperties.load(inputStream);
+        String version = avroProperties.getProperty("version");
+        if (version != null) {
+          return version;
+        }
+      }
+    } catch (Exception ignored) {
+      // Ignoring the exception and falling back to the manifest-based version 
below
+    }
+    return Schema.class.getPackage().getImplementationVersion();

Review Comment:
   Strongly agree with `not just a narrower NPE - it poisons a static 
initializer.`
   I'm thinking better to go with adding NULL guard in those helpers



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