Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

Fixed a NullPointerException case possible on Index Export

lucciomane5858bc8c8d3
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;