sstrickx / yahoofinance-api

Java Client API for Yahoo Finance
MIT License
507 stars 222 forks source link

NumberFormatException for stock.getHistory(from, to, Interval.DAILY) #168

Open nmicra opened 4 years ago

nmicra commented 4 years ago

2020-10-19 21:32:38.439 [nioEventLoopGroup-4-1] DEBUG yahoofinance.Utils - Failed to parse: null java.lang.NumberFormatException: null at java.math.BigDecimal.(BigDecimal.java:497) at java.math.BigDecimal.(BigDecimal.java:383) at java.math.BigDecimal.(BigDecimal.java:809) at yahoofinance.Utils.getBigDecimal(Utils.java:82) at yahoofinance.histquotes2.HistQuotes2Request.parseCSVLine(HistQuotes2Request.java:150) at yahoofinance.histquotes2.HistQuotes2Request.getResult(HistQuotes2Request.java:139) at yahoofinance.Stock.getHistory(Stock.java:327)

When parsing line in HistQuotes2Request --> HistoricalQuote parseCSVLine(String line) the line may look like this "2020-10-18,null,null,null,null,null,null", and for this line parsing fails. I guess you get this kind of line every Sunday. Probably for holidays too.

Please consider to fix it in the following way: // Parse CSV

for (String line = br.readLine(); line != null; line = br.readLine()) {

            log.info("Parsing CSV line: " + Utils.unescape(line));
            if (line.endsWith("null,null,null,null,null,null")){
                continue;
            }
            HistoricalQuote quote = this.parseCSVLine(line);
            result.add(quote);
        }