From 08f5408ab4af277f5c9b84cbe0d2500b14609e6b Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 20 Mar 2017 00:19:20 +0100 Subject: [PATCH] chg: Explicitly bail on invalid lines in imported lists Change-Id: I71afe609e7f736d2e6b7a032a7e971b3b770395a --- .../wpia/gigi/util/HighFinancialValueFetcherAlexa.java | 10 +++++++++- .../gigi/util/HighFinancialValueFetcherUmbrella.java | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/util/club/wpia/gigi/util/HighFinancialValueFetcherAlexa.java b/util/club/wpia/gigi/util/HighFinancialValueFetcherAlexa.java index ae3ef536..398bde20 100644 --- a/util/club/wpia/gigi/util/HighFinancialValueFetcherAlexa.java +++ b/util/club/wpia/gigi/util/HighFinancialValueFetcherAlexa.java @@ -12,8 +12,16 @@ public class HighFinancialValueFetcherAlexa extends HighFinancialValueFetcher { @Override public void handle(String line, PrintWriter fos) { String[] parts = line.split(","); + // Assert that the value before the "," is an integer - Integer.parseInt(parts[0]); + try { + if (Integer.parseInt(parts[0]) < 1) { + throw new NumberFormatException("We expect a number greater then zero for the first column."); + } + } catch (NumberFormatException nfe) { + // Bail on lines with invalid first field + throw new Error("Invalid format of first column.", nfe); + } emit(fos, parts[1]); System.out.println(parts[1]); diff --git a/util/club/wpia/gigi/util/HighFinancialValueFetcherUmbrella.java b/util/club/wpia/gigi/util/HighFinancialValueFetcherUmbrella.java index 321c3df4..40662e3b 100644 --- a/util/club/wpia/gigi/util/HighFinancialValueFetcherUmbrella.java +++ b/util/club/wpia/gigi/util/HighFinancialValueFetcherUmbrella.java @@ -15,8 +15,16 @@ public class HighFinancialValueFetcherUmbrella extends HighFinancialValueFetcher @Override public void handle(String line, PrintWriter fos) { String[] parts = line.split(","); + // Assert that the value before the "," is an integer - Integer.parseInt(parts[0]); + try { + if (Integer.parseInt(parts[0]) < 1) { + throw new NumberFormatException("We expect a number greater then zero for the first column."); + } + } catch (NumberFormatException nfe) { + // Bail on lines with invalid first field + throw new Error("Invalid format of first column.", nfe); + } String registrablePart = PublicSuffixes.getInstance().getRegistrablePart(parts[1]); if (registrablePart != null && printed.add(registrablePart)) { -- 2.39.2