From 387e0d272cbfcba12bf917e52910e67890f5313f Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 31 Jul 2016 14:17:02 +0200 Subject: [PATCH] chg: Proper error reporting in cases where the Public Suffix List cannot be read Change-Id: I8dc86c979573cc0b9f4dab27a9e53c19baa9ae4f --- src/org/cacert/gigi/util/PublicSuffixes.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/org/cacert/gigi/util/PublicSuffixes.java b/src/org/cacert/gigi/util/PublicSuffixes.java index 51c2edf2..19c7b1dc 100644 --- a/src/org/cacert/gigi/util/PublicSuffixes.java +++ b/src/org/cacert/gigi/util/PublicSuffixes.java @@ -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 suffixes = new HashSet<>(); + private HashSet suffixes = new HashSet<>(); - HashSet wildcards = new HashSet<>(); + private HashSet wildcards = new HashSet<>(); - HashSet exceptions = new HashSet<>(); + private HashSet 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; } + } -- 2.39.2