Why does IndexReader's maxDoc() return an 'incorrect' number of documents sometimes?

Otis Gospodnetic

According to the Javadoc for IndexReader maxDoc() method "returns one greater than the largest possible document number".
In other words, the number returned by maxDoc() does not necessarily match the actual number of undeleted documents in the index.

Deleted documents do not get removed from the index immediately, unless you call optimize().