]> WPIA git - gigi.git/commitdiff
chg: Proper error reporting in cases where the Public Suffix List cannot be read
authorBenny Baumann <BenBE1987@gmx.net>
Sun, 31 Jul 2016 12:17:02 +0000 (14:17 +0200)
committerBenny Baumann <BenBE1987@gmx.net>
Sun, 31 Jul 2016 15:03:14 +0000 (17:03 +0200)
Change-Id: I8dc86c979573cc0b9f4dab27a9e53c19baa9ae4f

src/org/cacert/gigi/util/PublicSuffixes.java

index 51c2edf2acb53a90a22a0021729dd08c73a63d9f..19c7b1dc952d15bf6255f98209c0ce7ebe1e1a5d 100644 (file)
@@ -2,24 +2,31 @@ package org.cacert.gigi.util;
 
 import java.io.BufferedReader;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.net.IDN;
 import java.util.HashSet;
 
 public class PublicSuffixes {
 
-    HashSet<String> suffixes = new HashSet<>();
+    private HashSet<String> suffixes = new HashSet<>();
 
-    HashSet<String> wildcards = new HashSet<>();
+    private HashSet<String> wildcards = new HashSet<>();
 
-    HashSet<String> exceptions = new HashSet<>();
+    private HashSet<String> exceptions = new HashSet<>();
 
-    private static final String url = "https://publicsuffix.org/list/effective_tld_names.dat";
+    static final String url = "https://publicsuffix.org/list/effective_tld_names.dat";
 
     private static PublicSuffixes instance;
 
     private static PublicSuffixes generateDefault() throws IOException {
-        try (BufferedReader br = new BufferedReader(new InputStreamReader(PublicSuffixes.class.getResourceAsStream("effective_tld_names.dat"), "UTF-8"))) {
+        InputStream res = PublicSuffixes.class.getResourceAsStream("effective_tld_names.dat");
+
+        if (null == res) {
+            throw new Error("Public Suffix List could not be loaded.");
+        }
+
+        try (BufferedReader br = new BufferedReader(new InputStreamReader(res, "UTF-8"))) {
             return new PublicSuffixes(br);
         }
     }
@@ -128,4 +135,5 @@ public class PublicSuffixes {
         }
         return false;
     }
+
 }