Index: lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java =================================================================== --- lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java (revision 1065066) +++ lucene/src/java/org/apache/lucene/search/cache/IntValuesCreator.java (working copy) @@ -75,45 +75,50 @@ } @Override - public synchronized IntValues validate(IntValues entry, IndexReader reader) throws IOException { + public IntValues validate(IntValues entry, IndexReader reader) throws IOException { boolean ok = false; - - if( hasOption(OPTION_CACHE_VALUES) ) { - ok = true; - if( entry.values == null ) { - fillIntValues(entry, reader, field); + + synchronized (entry) { + if( hasOption(OPTION_CACHE_VALUES) ) { + ok = true; + if( entry.values == null ) { + fillIntValues(entry, reader, field, parser); + } + else { + synchronized (this) { + assertSameParser( entry, parser ); + } + } } - else { - assertSameParser( entry, parser ); + if( hasOption(OPTION_CACHE_BITS) ) { + ok = true; + if( entry.valid == null ) { + fillValidBits(entry, reader, field); + } } } - if( hasOption(OPTION_CACHE_BITS) ) { - ok = true; - if( entry.valid == null ) { - fillValidBits(entry, reader, field); - } - } if( !ok ) { throw new RuntimeException( "the config must cache values and/or bits" ); } return entry; } - protected void fillIntValues( IntValues vals, IndexReader reader, String field ) throws IOException + protected void fillIntValues( IntValues vals, IndexReader reader, String field, IntParser parser ) throws IOException { if( parser == null ) { try { - parser = FieldCache.DEFAULT_INT_PARSER; - fillIntValues( vals, reader, field ); + fillIntValues( vals, reader, field, FieldCache.DEFAULT_INT_PARSER ); return; } catch (NumberFormatException ne) { - vals.parserHashCode = null; - parser = FieldCache.NUMERIC_UTILS_INT_PARSER; - fillIntValues( vals, reader, field ); + fillIntValues( vals, reader, field, FieldCache.NUMERIC_UTILS_INT_PARSER ); return; } } + + vals.numDocs = 0; + vals.numTerms = 0; + setParserAndResetCounts(vals, parser); Terms terms = MultiFields.getTerms(reader, field); @@ -161,5 +166,18 @@ if( vals.valid == null && vals.numDocs < 1 ) { vals.valid = new Bits.MatchNoBits( maxDoc ); } + + + synchronized (this) { + int parserHashCode = parser.hashCode(); + if( vals.parserHashCode != null && vals.parserHashCode != parserHashCode ) { + throw new RuntimeException( "Parser changed in subsequent call. " + +vals.parserHashCode+" != "+parserHashCode + " :: " + parser ); + } + this.parser = parser; + } + + + } } \ No newline at end of file