stevenzwu commented on code in PR #9452: URL: https://github.com/apache/iceberg/pull/9452#discussion_r1462236676
########## flink/v1.16/flink/src/main/java/org/apache/iceberg/flink/util/FlinkPackage.java: ########## @@ -18,16 +18,44 @@ */ package org.apache.iceberg.flink.util; +import java.util.concurrent.atomic.AtomicReference; import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting; public class FlinkPackage { - /** Choose {@link DataStream} class because it is one of the core Flink API. */ - private static final String VERSION = DataStream.class.getPackage().getImplementationVersion(); + + private static final AtomicReference<String> VERSION = new AtomicReference<>(); + public static final String FLINK_UNKNOWN_VERSION = "FLINK-UNKNOWN-VERSION"; private FlinkPackage() {} /** Returns Flink version string like x.y.z */ public static String version() { - return VERSION; + if (null == VERSION.get()) { Review Comment: why don't we move the try-catch/null handling to an `initVersion` method? ``` private static final String VERSION = initVersion() ... private static String initVersion() { String detectedVersion = null; try { detectedVersion = versionFromJar(); // use unknown version in case exact implementation version can't be found from the jar // (this can happen if the DataStream class appears multiple times in the same classpath // such as with shading) detectedVersion = detectedVersion != null ? detectedVersion : FLINK_UNKNOWN_VERSION; } catch (Exception e) { detectedVersion = FLINK_UNKNOWN_VERSION; } return detectedVersion; } ``` -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org