Index: lucene/src/test/org/apache/lucene/search/TestWildcard.java =================================================================== --- lucene/src/test/org/apache/lucene/search/TestWildcard.java (revision 988620) +++ lucene/src/test/org/apache/lucene/search/TestWildcard.java (working copy) @@ -200,6 +200,26 @@ } /** + * LUCENE-2620 + */ + public void testLotsOfAsterisks() + throws IOException { + Directory indexStore = getIndexStore("body", new String[] + {"metal", "metals"}); + IndexSearcher searcher = new IndexSearcher(indexStore, true); + StringBuilder term = new StringBuilder(); + term.append("m"); + for (int i = 0; i < 512; i++) + term.append("*"); + term.append("tal"); + Query query3 = new WildcardQuery(new Term("body", term.toString())); + + assertMatches(searcher, query3, 1); + searcher.close(); + indexStore.close(); + } + + /** * Tests Wildcard queries with a question mark. * * @throws IOException if an error occurs Index: lucene/src/java/org/apache/lucene/search/WildcardTermEnum.java =================================================================== --- lucene/src/java/org/apache/lucene/search/WildcardTermEnum.java (revision 988620) +++ lucene/src/java/org/apache/lucene/search/WildcardTermEnum.java (working copy) @@ -168,8 +168,9 @@ // if (pattern.charAt(p) == WILDCARD_STRING) { - // Look at the character beyond the '*'. - ++p; + // Look at the character beyond the '*' characters. + while (p < pattern.length() && pattern.charAt(p) == WILDCARD_STRING) + ++p; // Examine the string, starting at the last character. for (int i = string.length(); i >= s; --i) {