justinmclean opened a new issue, #10128:
URL: https://github.com/apache/gravitino/issues/10128

   ### What would you like to be improved?
   
   H2Database#getStoragePath builds a relative path with 
Paths.get(System.getenv("GRAVITINO_HOME"), dbPath). If GRAVITINO_HOME is not 
set, this can throw at runtime during H2 initialization, causing 
startup/configuration failure instead of handling the path safely.
   
   ### How should we improve?
   
   Guard GRAVITINO_HOME before building the path for relative storagePath 
values. i.e., if GRAVITINO_HOME is null/blank, throw a clear 
IllegalArgumentException explaining that relative paths require GRAVITINO_HOME.
   
   Here's a possible unit test to help:
   ```
   public class TestH2Database {
   
     @Test
     public void testGetStoragePathWithRelativePathWhenGravitinoHomeMissing() 
throws Exception {
       String javaBin = System.getProperty("java.home") + "/bin/java";
       String classPath = System.getProperty("java.class.path");
       String className =
           
"org.apache.gravitino.storage.relational.database.H2DatabaseStoragePathProbe";
   
       ProcessBuilder pb = new ProcessBuilder(javaBin, "-cp", classPath, 
className);
       pb.environment().remove("GRAVITINO_HOME");
       int exitCode = pb.start().waitFor();
   
       Assertions.assertEquals(
           0,
           exitCode,
           "Expected relative storage path resolution to work even when 
GRAVITINO_HOME is unset");
     }
   }
   
   class H2DatabaseStoragePathProbe {
     public static void main(String[] args) {
       try {
         Config config = new Config(false) {};
         config.set(Configs.ENTITY_RELATIONAL_JDBC_BACKEND_PATH, 
"relative-db-path");
   
         Method getStoragePath = 
H2Database.class.getDeclaredMethod("getStoragePath", Config.class);
         getStoragePath.setAccessible(true);
         getStoragePath.invoke(null, config);
         System.exit(0);
       } catch (Throwable t) {
         System.exit(1);
       }
     }
   }
   
   ```


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