Otis, Here a the test program that will generate the null pointer and the requested diff. Hope they are helpful.
Thanks, Rasik Pandey -----Message d'origine----- De : Otis Gospodnetic [mailto:[EMAIL PROTECTED]] Envoy� : jeudi 12 septembre 2002 18:23 � : Lucene Developers List Cc : [EMAIL PROTECTED] Objet : Re: Nullpointer in code Rasik, Thanks for feedback, but that stuff is a bit hard to read. The best way to help would be to write a class that demonstrates this, then fix your code to work, then make a diff between your fixed code and the code in the CVS, and finally, it would be great to have a unit test for it, but I can write that later. Thanks, Otis --- Rasik Pandey <[EMAIL PROTECTED]> wrote: > Developers, > I am encountering a null pointer exception when executing a wild card > query search on an empty index which doesn't contain any terms and of > course not the Term generated from the wild card query (ie the > WildCardTermEnum has an empty "actualEnum"). Please see below for > what i > propose to be the fix (simple). I assume that this is sufficient or > would a change in one of the SegmentReader or TermsInfosReader > classes > be more appropriate (not likely)? > > I do not have access to commit this change, so if you deem that it is > necessary can you please make the modification. > > Cheers, > Rasik Pandey > > Basically in the constructor of WildCardTermEnum the constructor > calls; > > setEnum(reader.terms(new Term(searchTerm.field(), pre))); > ----or > super.setEnum(an empty termEnum); or FilteredTermEnum.setEnum(an > empty termEnum); > > > Then in FilteredTermnEnum: > protected void setEnum(TermEnum actualEnum) throws IOException { > this.actualEnum = actualEnum; > // Find the first term that matches > > > !!!!!!!!the result of actualEnum.term(); is null in my case!!!!!!!!! > Term term = actualEnum.term(); > > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! > > > !!!!!!!!!!!!the below line leads to the null pointer!!!!!!!!!! > if (termCompare(term)) > !!!!!!!!!!!!!!!!!!!!see > below!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! > > currentTerm = term; > else next(); > } > > > Then back in WildCardTermEnum: > > final protected boolean termCompare(Term term) { > !!!!!!!!!!!the below line should test to ensure that "term" is > not null!!!!!! > if (field == term.field()) { > !!!!!!!!!!!!!!!!see below line for the simple > fix!!!!!!!!!!!!!!!!!!!!!!!!!!!! > > !!!!!!!!!!!!!!!!!below is the changed line for the simple > fix!!!!!!!!!!!!!!!!!!!!!!!! > if (term != null && field == term.field()) { > > !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! > !!!!!!!!!!!!! > String searchText = term.text(); > if (searchText.startsWith(pre)) { > return wildcardEquals(text, 0, searchText, preLen); > } > } > endEnum = true; > return false; > } > > > -- > To unsubscribe, e-mail: > <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: > <mailto:[EMAIL PROTECTED]> > __________________________________________________ Yahoo! - We Remember 9-11: A tribute to the more than 3,000 lives lost http://dir.remember.yahoo.com/tribute -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
TestWildcardTermEnum.java
Description: Binary data
C:\Program Files\GNU\WinCvs 1.2\cvs.exe diff -r 1.1 WildcardTermEnum.java
Index: WildcardTermEnum.java
===================================================================
RCS file:
/home/cvspublic/jakarta-lucene/src/java/org/apache/lucene/search/WildcardTermEnum.java,v
retrieving revision 1.1
diff -r1.1 WildcardTermEnum.java
62,65c62,68
< /** Subclass of FilteredTermEnum for enumerating all terms that match the specified
wildcard filter term.
<
< <p>Term enumerations are always ordered by Term.compareTo(). Each term in
< the enumeration is greater than all that precede it. */
---
> /**
> * Subclass of FilteredTermEnum for enumerating all terms that match the
> * specified wildcard filter term.
> * <p>
> * Term enumerations are always ordered by Term.compareTo(). Each term in
> * the enumeration is greater than all that precede it.
> */
74c77
<
---
>
93c96
<
---
>
95c98
< if (field == term.field()) {
---
> if (term != null && field == term.field()) {
104c107
<
---
>
108c111
<
---
>
112c115
<
---
>
116c119
<
---
>
119,139c122,219
<
< public static final boolean wildcardEquals(String pattern, int patternIdx, String
string, int stringIdx) {
< for ( int p = patternIdx; ; ++p ) {
< for ( int s = stringIdx; ; ++p, ++s ) {
< boolean sEnd = (s >= string.length());
< boolean pEnd = (p >= pattern.length());
<
< if (sEnd && pEnd) return true;
< if (sEnd || pEnd) break;
< if (pattern.charAt(p) == WILDCARD_CHAR) continue;
< if (pattern.charAt(p) == WILDCARD_STRING) {
< int i;
< ++p;
< for (i = string.length(); i >= s; --i)
< if (wildcardEquals(pattern, p, string, i))
< return true;
< break;
< }
< if (pattern.charAt(p) != string.charAt(s)) break;
< }
< return false;
---
>
> /**
> * Determines if a word matches a wildcard pattern.
> * <small>Work released by Granta Design Ltd after originally being done on
> * company time.</small>
> */
> public static final boolean wildcardEquals(String pattern, int patternIdx,
> String string, int stringIdx)
> {
> for (int p = patternIdx; ; ++p)
> {
> for (int s = stringIdx; ; ++p, ++s)
> {
> // End of string yet?
> boolean sEnd = (s >= string.length());
> // End of pattern yet?
> boolean pEnd = (p >= pattern.length());
>
> // If we're looking at the end of the string...
> if (sEnd)
> {
> // Assume the only thing left on the pattern is/are wildcards
> boolean justWildcardsLeft = true;
>
> // Current wildcard position
> int wildcardSearchPos = p;
> // While we haven't found the end of the pattern,
> // and haven't encountered any non-wildcard characters
> while (wildcardSearchPos < pattern.length() && justWildcardsLeft)
> {
> // Check the character at the current position
> char wildchar = pattern.charAt(wildcardSearchPos);
> // If it's not a wildcard character, then there is more
> // pattern information after this/these wildcards.
>
> if (wildchar != WILDCARD_CHAR &&
> wildchar != WILDCARD_STRING)
> {
> justWildcardsLeft = false;
> }
> else
> {
> // Look at the next character
> wildcardSearchPos++;
> }
> }
>
> // This was a prefix wildcard search, and we've matched, so
> // return true.
> if (justWildcardsLeft)
> {
> return true;
> }
> }
>
> // If we've gone past the end of the string, or the pattern,
> // return false.
> if (sEnd || pEnd)
> {
> break;
> }
>
> // Match a single character, so continue.
> if (pattern.charAt(p) == WILDCARD_CHAR)
> {
> continue;
> }
>
> //
> if (pattern.charAt(p) == WILDCARD_STRING)
> {
> // Look at the character beyond the '*'.
> ++p;
> // Examine the string, starting at the last character.
> for (int i = string.length(); i >= s; --i)
> {
> if (wildcardEquals(pattern, p, string, i))
> {
> return true;
> }
> }
> break;
> }
> if (pattern.charAt(p) != string.charAt(s))
> {
> break;
> }
> }
> return false;
> }
> }
>
> public void close() throws IOException
> {
> super.close();
> searchTerm = null;
> field = null;
> text = null;
141,148d220
< }
<
< public void close() throws IOException {
< super.close();
< searchTerm = null;
< field = null;
< text = null;
< }
CVS command finished execution
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
