From e5858bc8c8d330b7d25eafd1d5328b48dfbb1618 Mon Sep 17 00:00:00 2001 From: luccioman Date: Fri, 17 Feb 2017 11:09:30 +0100 Subject: [PATCH] Fixed a NullPointerException case possible on Index Export As reported by Palulukas in YaCy forum (http://forum.yacy-websuche.de/viewtopic.php?f=18&t=5944&sid=dcef5b899ab4aa9b40e3a3d158c13aed#p33454) the Index Export operation can fails, notably when the Solr index contains one or more documents with empty (despite required) "load_date_dt" field. This fixes the export failure when the situation finally occurs, but more should be done to harden verifications on minimum required fields. --- source/net/yacy/search/index/Fulltext.java | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/source/net/yacy/search/index/Fulltext.java b/source/net/yacy/search/index/Fulltext.java index 3d6a79da1..4cb8cb04d 100644 --- a/source/net/yacy/search/index/Fulltext.java +++ b/source/net/yacy/search/index/Fulltext.java @@ -690,8 +690,26 @@ public final class Fulltext { SolrDocument lastdoc = lastdoclist.get(0); Object firstdateobject = firstdoc.getFieldValue(CollectionSchema.load_date_dt.getSolrFieldName()); Object lastdateobject = lastdoc.getFieldValue(CollectionSchema.load_date_dt.getSolrFieldName()); - Date firstdate = (Date) firstdateobject; - Date lastdate = (Date) lastdateobject; + + /* When firstdate or lastdate is null, we use a default one just to generate a proper dump file path + * This should not happen because load_date_dt field is mandatory in the main Solr schema, + * but for some reason some documents might end up here with an empty load_date_dt field value */ + final Date firstdate; + if(firstdateobject instanceof Date) { + firstdate = (Date) firstdateobject; + } else { + ConcurrentLog.warn("Fulltext", "The required field " + CollectionSchema.load_date_dt.getSolrFieldName() + " is empty on document with id : " + + firstdoc.getFieldValue(CollectionSchema.id.getSolrFieldName())); + firstdate = new Date(0); + } + final Date lastdate; + if(lastdateobject instanceof Date) { + lastdate = (Date) lastdateobject; + } else { + ConcurrentLog.warn("Fulltext", "The required field " + CollectionSchema.load_date_dt.getSolrFieldName() + " is empty on document with id : " + + lastdoc.getFieldValue(CollectionSchema.id.getSolrFieldName())); + lastdate = new Date(0); + } String s = new File(path, yacy_dump_prefix + "f" + GenericFormatter.FORMAT_SHORT_MINUTE.format(firstdate) + "_" + "l" + GenericFormatter.FORMAT_SHORT_MINUTE.format(lastdate) + "_" + @@ -716,6 +734,11 @@ public final class Fulltext { this.exportthread.start(); return this.exportthread; } + + public static void main(String args[]) { + Date firstdate = null; + System.out.println(GenericFormatter.FORMAT_SHORT_MINUTE.format(firstdate)); + } public Export export() { return this.exportthread;