From 4f3c15eb042969c3945a48867eeded454893c0c6 Mon Sep 17 00:00:00 2001
From: zzz <zzz@mail.i2p>
Date: Mon, 4 Jul 2011 22:07:13 +0000
Subject: [PATCH] use HostsTxtNamingService if default fails to initialize

---
 .../java/src/net/i2p/client/naming/NamingService.java | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/core/java/src/net/i2p/client/naming/NamingService.java b/core/java/src/net/i2p/client/naming/NamingService.java
index 0aaf88d09a..aa5ecb4bf8 100644
--- a/core/java/src/net/i2p/client/naming/NamingService.java
+++ b/core/java/src/net/i2p/client/naming/NamingService.java
@@ -36,6 +36,7 @@ public abstract class NamingService {
     /** what classname should be used as the naming service impl? */
     public static final String PROP_IMPL = "i2p.naming.impl";
     private static final String DEFAULT_IMPL = "net.i2p.client.naming.BlockfileNamingService";
+    private static final String BACKUP_IMPL = "net.i2p.client.naming.HostsTxtNamingService";
     
     /** 
      * The naming service should only be constructed and accessed through the 
@@ -434,8 +435,14 @@ public abstract class NamingService {
             instance = (NamingService)con.newInstance(new Object[] { context });
         } catch (Exception ex) {
             Log log = context.logManager().getLog(NamingService.class);
-            log.error("Cannot load naming service " + impl + ", only .b32.i2p lookups will succeed", ex);
-            instance = new DummyNamingService(context); // fallback
+            // Blockfile may throw RuntimeException but HostsTxt won't
+            if (!impl.equals(BACKUP_IMPL)) {
+                log.error("Cannot load naming service " + impl + ", using HostsTxtNamingService", ex);
+                instance = new HostsTxtNamingService(context);
+            } else {
+                log.error("Cannot load naming service " + impl + ", only .b32.i2p lookups will succeed", ex);
+                instance = new DummyNamingService(context);
+            }
         }
         return instance;
     }
-- 
GitLab