mirror of https://github.com/apache/lucene.git
LUCENE-1280: prevent NPE in PhraseQuery.toString() when the PhraseQuery is empty
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@688689 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3034575f66
commit
85102bd84a
|
@ -256,7 +256,7 @@ public class PhraseQuery extends Query {
|
||||||
/** Prints a user-readable version of this query. */
|
/** Prints a user-readable version of this query. */
|
||||||
public String toString(String f) {
|
public String toString(String f) {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
if (!field.equals(f)) {
|
if (field != null && !field.equals(f)) {
|
||||||
buffer.append(field);
|
buffer.append(field);
|
||||||
buffer.append(":");
|
buffer.append(":");
|
||||||
}
|
}
|
||||||
|
|
|
@ -544,5 +544,13 @@ public class TestPhraseQuery extends LuceneTestCase {
|
||||||
//assertTrue("reversed scores higher in palindrome",score1+SCORE_COMP_THRESH<score3);
|
//assertTrue("reversed scores higher in palindrome",score1+SCORE_COMP_THRESH<score3);
|
||||||
//assertEquals("ordered or reversed does not matter",score2, score3, SCORE_COMP_THRESH);
|
//assertEquals("ordered or reversed does not matter",score2, score3, SCORE_COMP_THRESH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LUCENE-1280
|
||||||
|
public void testEmptyPhraseQuery() throws Throwable {
|
||||||
|
final PhraseQuery q1 = new PhraseQuery();
|
||||||
|
final BooleanQuery q2 = new BooleanQuery();
|
||||||
|
q2.add(new PhraseQuery(), BooleanClause.Occur.MUST);
|
||||||
|
q2.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue