From 85102bd84af1bb060166108f4ab4539edeca1e6f Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 25 Aug 2008 10:02:16 +0000 Subject: [PATCH] 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 --- src/java/org/apache/lucene/search/PhraseQuery.java | 2 +- src/test/org/apache/lucene/search/TestPhraseQuery.java | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/lucene/search/PhraseQuery.java b/src/java/org/apache/lucene/search/PhraseQuery.java index dc9bed4829e..efcca47e2b2 100644 --- a/src/java/org/apache/lucene/search/PhraseQuery.java +++ b/src/java/org/apache/lucene/search/PhraseQuery.java @@ -256,7 +256,7 @@ public class PhraseQuery extends Query { /** Prints a user-readable version of this query. */ public String toString(String f) { StringBuffer buffer = new StringBuffer(); - if (!field.equals(f)) { + if (field != null && !field.equals(f)) { buffer.append(field); buffer.append(":"); } diff --git a/src/test/org/apache/lucene/search/TestPhraseQuery.java b/src/test/org/apache/lucene/search/TestPhraseQuery.java index 21714c29c58..e5ab3d8cae0 100644 --- a/src/test/org/apache/lucene/search/TestPhraseQuery.java +++ b/src/test/org/apache/lucene/search/TestPhraseQuery.java @@ -544,5 +544,13 @@ public class TestPhraseQuery extends LuceneTestCase { //assertTrue("reversed scores higher in palindrome",score1+SCORE_COMP_THRESH