After deleting an entity lucene index updating fails due to NullPointerException

Description

When entities are deleted, I noticed an exception with a rather large stack trace (below), which appears to be caused by the fact that Lucene is told to remove from the index a document with a null id.

After (quite) a bit of digging, I believe the source is the top of this stack trace:

Specifically, org.hibernate.search.engine.DocumentBuilderIndexedEntity.getId(Object) does:

As far as I can tell, unproxy(entity) will return an entity with a null id if called during postRemove; the returned result is null, although the debugger says that entity.id actually contains the correct (non-null, pre-deletion) value.

org.hibernate.search.engine.WorkPlan.PerClassWork.extractProperId(Work<T>), right below the top of the stack, does:

This condition fails and goes into the "else" block, which is unfortunate, because work.getId() actually contains the correct value.

The error doesn't occur right away: org.hibernate.search.engine.WorkPlan.PerClassWork.addWork(Work<T>) (a bit below the top of the stack) calls "entityById.put( id, entityWork );", with id=null due to the above.

A while later the following happens (the bottom two items are the same as the stack trace above):

The entry at the top belongs to

The argument delete is true and id is null (it's the value of WorkPlan$PerClassWork<T>.enqueueLuceneWork(List<LuceneWork>) gets it from the documentBuilder.getId(entity) call mentioned above). A little while later the actual exception is triggered:

org.apache.lucene.index.Term.compareTo fails because this.id is null, having received its value a bit earlier from the null document id above. (Technically, I think this also a bug in lucene; surrounding code, for example Term.equals, does test for null, so either Term.compareTo should do it, or the Term should have been checked for null quite a while earlier. Anyway, the results would have been the same, except for easier debugging.)

Environment

Hibernate 3.4.0 (on MySQL 5.1.54, but any database is affected AFAIK)

Assignee

Hardy Ferentschik

Reporter

Bogdan Butnaru

Labels

None

Suitable for new contributors

Yes, likely

Pull Request

None

Feedback Requested

None

Components

Affects versions

Priority

Critical
Configure