This is an automated email from the ASF dual-hosted git repository.

jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new 7c1eb871ee [#10762] fix(common): Lazy-initialize Version to fix 
TestVersion without jar task (#10779)
7c1eb871ee is described below

commit 7c1eb871ee79e12dda458030c6b699eb3a413cc8
Author: Sachin Ranjalkar <[email protected]>
AuthorDate: Tue Apr 14 17:34:04 2026 +0530

    [#10762] fix(common): Lazy-initialize Version to fix TestVersion without 
jar task (#10779)
    
    ### What changes were proposed in this pull request?
    
    Replace eager static initialization of `Version.INSTANCE` with the
    initialization-on-demand holder idiom. This ensures
    `parseVersionNumber()` can be called without triggering the properties
    file load.
    
    ### Why are the changes needed?
    
    `TestVersion` fails when tests are run directly (`./gradlew clean
    :common:test -PskipITs`) without first running the `jar` task. The
    `gravitino-build-info.properties` file is only generated inside `jar {
    doFirst }`, not during `processResources`. Since `test` does not depend
    on `jar`, the file is absent, causing `Version`'s static initializer to
    throw — even though all `TestVersion` methods only call
    `parseVersionNumber()`, which never uses `INSTANCE`.
    
    The holder pattern is already established in this codebase by
    `ObjectMapperProvider` and `GravitinoEnv`.
    
    Fix: #10762
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    `./gradlew clean :common:test -PskipITs --tests
    "org.apache.gravitino.TestVersion"` — all 4 tests pass without a prior
    `jar` task.
---
 common/src/main/java/org/apache/gravitino/Version.java | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/common/src/main/java/org/apache/gravitino/Version.java 
b/common/src/main/java/org/apache/gravitino/Version.java
index f62252f552..9201ac6f8f 100644
--- a/common/src/main/java/org/apache/gravitino/Version.java
+++ b/common/src/main/java/org/apache/gravitino/Version.java
@@ -38,7 +38,9 @@ public class Version {
   private static final Pattern PATTERN =
       
Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)(?:rc(0|[1-9]\\d*)|-.*|\\.([a-zA-Z].*))?$");
 
-  private static final Version INSTANCE = new Version();
+  private static class InstanceHolder {
+    private static final Version INSTANCE = new Version();
+  }
 
   private final VersionInfo versionInfo;
   private final VersionDTO versionDTO;
@@ -74,14 +76,14 @@ public class Version {
    * @return the current versionInfo
    */
   public static VersionInfo getCurrentVersion() {
-    return INSTANCE.versionInfo;
+    return InstanceHolder.INSTANCE.versionInfo;
   }
 
   /**
    * @return the current version DTO
    */
   public static VersionDTO getCurrentVersionDTO() {
-    return INSTANCE.versionDTO;
+    return InstanceHolder.INSTANCE.versionDTO;
   }
 
   /**

Reply via email to