Buggy code:
public class DirectoryTaxonomyWriter implements TaxonomyWriter { public static final String INDEX_CREATE_TIME = "index.create.time" ; private Directory dir ; private IndexWriter indexWriter ; private int nextID ; private char delimiter = Consts . DEFAULT_DELIMITER ; private DirectoryTaxonomyWriter . SinglePositionTokenStream parentStream = new DirectoryTaxonomyWriter . SinglePositionTokenStream ( Consts . PAYLOAD_PARENT ) ; private Field parentStreamField ; private Field fullPathField ; private TaxonomyWriterCache cache ; private boolean cacheIsComplete ; private DirectoryReader reader ; private int cacheMisses ; private String createTime ; private static Map < String , String > readCommitData ( Directory dir ) throws IOException { } public void setDelimiter ( char delimiter ) { } public static void unlock ( Directory directory ) throws IOException { } public DirectoryTaxonomyWriter ( Directory directory , OpenMode openMode , TaxonomyWriterCache cache ) throws IOException { } protected IndexWriter openIndexWriter ( Directory directory , IndexWriterConfig config ) throws IOException { } protected IndexWriterConfig createIndexWriterConfig ( OpenMode openMode ) { } private synchronized void openInternalReader ( ) throws IOException { } public DirectoryTaxonomyWriter ( Directory directory , OpenMode openMode ) throws IOException , CorruptIndexException , LockObtainFailedException { } public static TaxonomyWriterCache defaultTaxonomyWriterCache ( ) { } public DirectoryTaxonomyWriter ( Directory d ) throws IOException , CorruptIndexException , LockObtainFailedException { } @ Override public synchronized void close ( ) throws IOException , CorruptIndexException { } private void doClose ( ) throws IOException , CorruptIndexException { } protected synchronized void closeResources ( ) throws IOException { } protected int findCategory ( CategoryPath categoryPath ) throws IOException { } private int findCategory ( CategoryPath categoryPath , int prefixLen ) throws IOException { } @ Override public int addCategory ( CategoryPath categoryPath ) throws IOException { } private int internalAddCategory ( CategoryPath categoryPath , int length ) throws IOException { } protected final void ensureOpen ( ) { } private int addCategoryDocument ( CategoryPath categoryPath , int length , int parent ) throws IOException { <START_BUG> parentStream . set ( ( parent + 1 ) ) ; <END_BUG> Document d = new Document ( ) ; d . add ( parentStreamField ) ; fullPathField . setStringValue ( categoryPath . toString ( delimiter , length ) ) ; d . add ( fullPathField ) ; indexWriter . addDocument ( d ) ; int id = ( nextID ) ++ ; addToCache ( categoryPath , length , id ) ; getParentArray ( ) . add ( id , parent ) ; return id ; } private static class SinglePositionTokenStream extends TokenStream { private CharTermAttribute termAtt ; private PositionIncrementAttribute posIncrAtt ; private boolean returned ; public SinglePositionTokenStream ( String word ) { } public void set ( int val ) { } @ Override public boolean incrementToken ( ) throws IOException { } } private void addToCache ( CategoryPath categoryPath , int id ) throws IOException { } private void addToCache ( CategoryPath categoryPath , int prefixLen , int id ) throws IOException { } private synchronized void refreshInternalReader ( ) throws IOException { } @ Override public synchronized void commit ( ) throws IOException , CorruptIndexException { } private Map < String , String > combinedCommitData ( Map < String , String > userData ) { } @ Override public synchronized void commit ( Map < String , String > commitUserData ) throws IOException , CorruptIndexException { } @ Override public synchronized void prepareCommit ( ) throws IOException , CorruptIndexException { } @ Override public synchronized void prepareCommit ( Map < String , String > commitUserData ) throws IOException , CorruptIndexException { } @ Override public synchronized int getSize ( ) { } private boolean alreadyCalledFillCache = false ; public void setCacheMissesUntilFill ( int i ) { } private int cacheMissesUntilFill = 11 ; private boolean perhapsFillCache ( ) throws IOException { } private ParentArray parentArray ; private synchronized ParentArray getParentArray ( ) throws IOException { } @ Override public int getParent ( int ordinal ) throws IOException { } public void addTaxonomy ( Directory taxoDir , DirectoryTaxonomyWriter . OrdinalMap map ) throws IOException { } public static interface OrdinalMap { public void setSize ( int size ) throws IOException { } public void addMapping ( int origOrdinal , int newOrdinal ) throws IOException { } public void addDone ( ) throws IOException { } public int [ ] getMap ( ) throws IOException { } } public static final class MemoryOrdinalMap implements DirectoryTaxonomyWriter . OrdinalMap { int [ ] map ; @ Override public void setSize ( int taxonomySize ) { } @ Override public void addMapping ( int origOrdinal , int newOrdinal ) { } @ Override public void addDone ( ) { } @ Override public int [ ] getMap ( ) { } } public static final class DiskOrdinalMap implements DirectoryTaxonomyWriter . OrdinalMap { File tmpfile ; DataOutputStream out ; public DiskOrdinalMap ( File tmpfile ) throws FileNotFoundException { } @ Override public void addMapping ( int origOrdinal , int newOrdinal ) throws IOException { } @ Override public void setSize ( int taxonomySize ) throws IOException { } @ Override public void addDone ( ) throws IOException { } int [ ] map = null ; @ Override public int [ ] getMap ( ) throws IOException { } } @ Override public synchronized void rollback ( ) throws IOException { } public void replaceTaxonomy ( Directory taxoDir ) throws IOException { } public Directory getDirectory ( ) { } }

Fix:
parentStream . set ( Math . max ( ( parent + 1 ) , 1 ) ) ;