Permalink
Browse files

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.
  • Loading branch information...
luccioman committed Feb 17, 2017
1 parent 7e53860 commit e5858bc8c8d330b7d25eafd1d5328b48dfbb1618
Showing with 25 additions and 2 deletions.
  1. +25 −2 source/net/yacy/search/index/Fulltext.java
@@ -690,8 +690,26 @@ public Export export(Fulltext.ExportFormat format, String filter, String query,
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 Export export(final File f, final String filter, final String query, fina
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;

0 comments on commit e5858bc

Please sign in to comment.