lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r688689 - in /lucene/java/trunk/src: java/org/apache/lucene/search/PhraseQuery.java test/org/apache/lucene/search/TestPhraseQuery.java
Date Mon, 25 Aug 2008 10:02:16 GMT
Author: mikemccand
Date: Mon Aug 25 03:02:16 2008
New Revision: 688689

URL: http://svn.apache.org/viewvc?rev=688689&view=rev
Log:
LUCENE-1280: prevent NPE in PhraseQuery.toString() when the PhraseQuery is empty

Modified:
    lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java
    lucene/java/trunk/src/test/org/apache/lucene/search/TestPhraseQuery.java

Modified: lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java?rev=688689&r1=688688&r2=688689&view=diff
==============================================================================
--- lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java (original)
+++ lucene/java/trunk/src/java/org/apache/lucene/search/PhraseQuery.java Mon Aug 25 03:02:16
2008
@@ -256,7 +256,7 @@
   /** 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(":");
     }

Modified: lucene/java/trunk/src/test/org/apache/lucene/search/TestPhraseQuery.java
URL: http://svn.apache.org/viewvc/lucene/java/trunk/src/test/org/apache/lucene/search/TestPhraseQuery.java?rev=688689&r1=688688&r2=688689&view=diff
==============================================================================
--- lucene/java/trunk/src/test/org/apache/lucene/search/TestPhraseQuery.java (original)
+++ lucene/java/trunk/src/test/org/apache/lucene/search/TestPhraseQuery.java Mon Aug 25 03:02:16
2008
@@ -544,5 +544,13 @@
     //assertTrue("reversed scores higher in palindrome",score1+SCORE_COMP_THRESH<score3);
     //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();
+  }
   
 }



Mime
View raw message