HDDS-13735. DBConfigFromFile warns about trying to read from "" (#9093)
diff --git a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
index 4e7950e..b2ebf62 100644
--- a/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
+++ b/hadoop-hdds/framework/src/main/java/org/apache/hadoop/hdds/utils/db/DBConfigFromFile.java
@@ -82,7 +82,7 @@ public static File getConfigLocation() {
    */
   public static String getOptionsFileNameFromDB(String dbFileName) {
     Preconditions.checkNotNull(dbFileName);
-    return dbFileName + ".ini";
+    return dbFileName.isEmpty() ? "" : dbFileName + ".ini";
   }
 
   /**
@@ -113,6 +113,9 @@ public static String getOptionsFileNameFromDB(String dbFileName) {
    */
   public static ManagedDBOptions readDBOptionsFromFile(Path dbPath) throws RocksDBException {
     Path generatedDBPath = generateDBPath(dbPath);
+    if (generatedDBPath.toString().isEmpty()) {
+      return null;
+    }
     if (!generatedDBPath.toFile().exists()) {
       LOG.warn("Error trying to read generated rocksDB file: {}, file does not exists.", generatedDBPath);
       return null;
@@ -137,6 +140,9 @@ public static ManagedDBOptions readDBOptionsFromFile(Path dbPath) throws RocksDB
   public static ManagedColumnFamilyOptions readCFOptionsFromFile(Path optionsPath, String cfName)
       throws RocksDBException {
     Path generatedDBPath = generateDBPath(optionsPath);
+    if (generatedDBPath.toString().isEmpty()) {
+      return null;
+    }
     if (!generatedDBPath.toFile().exists()) {
       LOG.warn("Error trying to read column family options from file: {}, file does not exists.", generatedDBPath);
       return null;
@@ -173,6 +179,10 @@ private static void closeDescriptors(List<ColumnFamilyDescriptor> descriptors) {
    * @throws RocksDBException
    */
   private static Path generateDBPath(Path path) {
+    String dbPath = path == null ? "" : path.toString();
+    if (dbPath.isEmpty()) {
+      return Paths.get("");
+    }
     if (path.toFile().exists()) {
       LOG.debug("RocksDB path found: {}, opening db from it.", path);
       return path;
@@ -190,5 +200,4 @@ private static Path generateDBPath(Path path) {
     LOG.info("No RocksDB path found");
     return Paths.get("");
   }
-
 }
diff --git a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
index 9e092c6..72ac0c4 100644
--- a/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
+++ b/hadoop-hdds/framework/src/test/java/org/apache/hadoop/hdds/utils/db/TestDBConfigFromFile.java
@@ -80,6 +80,13 @@ public void readFromNonExistentFile() throws RocksDBException {
   }
 
   @Test
+  public void readFromEmptyFilePath() throws RocksDBException {
+    final DBOptions options = DBConfigFromFile.readDBOptionsFromFile(Paths.get(""));
+    // This has to return a Null, since the path is empty.
+    assertNull(options);
+  }
+
+  @Test
   public void readFromEmptyFile() throws IOException {
     File emptyFile = new File(Paths.get(System.getProperty(DBConfigFromFile.CONFIG_DIR)).toString(), "empty.ini");
     assertTrue(emptyFile.createNewFile());