Implementing a JMS based replication for my Lucene index with Hibernate search I am facing this issue.
When the master node as a consumer at the activeMQ-server fetching data and tries to update his index, this fails with a NullPointer and this following stack trace:
Quote:
2016-07-27 10:45:45,621 ERROR [Hibernate Search sync consumer thread for index users] (LogErrorHandler.java:67) HSEARCH000058: Exception occurred org.hibernate.search.exception.SearchException: Unable to update class com.sobis.cmdb.model.SettingDocu#8a81838755e43e0a0155e44f65e10000 in index.
Primary Failure:
Entity com.sobis.jaf.model.security.User Id 8a8183875597702d0155977117c20008 Work Type org.hibernate.search.backend.UpdateLuceneWork
Subsequent failures:
Entity com.sobis.jaf.model.security.User Id 8a8183875597702d0155977117c20008 Work Type org.hibernate.search.backend.UpdateLuceneWork
org.hibernate.search.exception.SearchException: Unable to update class com.sobis.jaf.model.security.User#8a8183875597702d0155977117c20008 in index.
at org.hibernate.search.backend.impl.lucene.works.UpdateExtWorkExecutor.performWork(UpdateExtWorkExecutor.java:77)
at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.performWork(LuceneBackendQueueTask.java:111)
at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.applyUpdates(LuceneBackendQueueTask.java:91)
at org.hibernate.search.backend.impl.lucene.LuceneBackendQueueTask.run(LuceneBackendQueueTask.java:46)
at org.hibernate.search.backend.impl.lucene.SyncWorkProcessor$Consumer.applyChangesets(SyncWorkProcessor.java:162)
at org.hibernate.search.backend.impl.lucene.SyncWorkProcessor$Consumer.run(SyncWorkProcessor.java:148)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at org.apache.lucene.index.TermsHashPerField.add(TermsHashPerField.java:150)
at org.apache.lucene.index.DefaultIndexingChain$PerField.invert(DefaultIndexingChain.java:661)
at org.apache.lucene.index.DefaultIndexingChain.processField(DefaultIndexingChain.java:344)
at org.apache.lucene.index.DefaultIndexingChain.processDocument(DefaultIndexingChain.java:300)
at org.apache.lucene.index.DocumentsWriterPerThread.updateDocument(DocumentsWriterPerThread.java:234)
at org.apache.lucene.index.DocumentsWriter.updateDocument(DocumentsWriter.java:450)
at org.apache.lucene.index.IndexWriter.updateDocument(IndexWriter.java:1475)
at org.hibernate.search.backend.impl.lucene.IndexWriterDelegate.updateDocument(IndexWriterDelegate.java:74)
at org.hibernate.search.backend.impl.lucene.works.UpdateExtWorkExecutor.performWork(UpdateExtWorkExecutor.java:71)
... 6 more
On further investigations I found out, that the error is caused by an
term attribute that is null after the method
setAttributeSource in the Lucene class
org.apache.lucene.index.FieldInvertState. In this method the attribute is retrieved by the method getAttribute.
The weird aspect is that on each try on different fields the termAttribute is null. The correct value for the termAttribute seems to be blank at this state.
Has anyone an idea, why this error occurs? What information do you need to understand this error? Can it be an configuration issue or is it more likely that it is a strange bug?Further investigations:
With the blank termAttribute fields in mind i added a null check to the method setAttributeSource and in case of null used addAttribute instead of getAttribute.
Code:
void setAttributeSource(AttributeSource attributeSource) {
if (this.attributeSource != attributeSource) {
this.attributeSource = attributeSource;
termAttribute = attributeSource.getAttribute(TermToBytesRefAttribute.class);
//added the nullcheck
if(termAttribute == null){
termAttribute = attributeSource.addAttribute(TermToBytesRefAttribute.class);
}
posIncrAttribute = attributeSource.addAttribute(PositionIncrementAttribute.class);
offsetAttribute = attributeSource.addAttribute(OffsetAttribute.class);
payloadAttribute = attributeSource.getAttribute(PayloadAttribute.class);
}
}
Now all works fine with this fix. It seems, that no required information are lost this way, but I'm not sure.