You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2014/01/05 21:53:24 UTC

svn commit: r1555628 - in /lucene/dev/branches/branch_4x: ./ lucene/ lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/ lucene/facet/src/java/org/apache/lucene/facet/sortedset/ lucene/facet/src/java/org/apache/lucene/facet/taxonomy/ lucene/fa...

Author: mikemccand
Date: Sun Jan  5 20:53:23 2014
New Revision: 1555628

URL: http://svn.apache.org/r1555628
Log:
LUCENE-5339: also catch invalid components in *FacetField

Modified:
    lucene/dev/branches/branch_4x/   (props changed)
    lucene/dev/branches/branch_4x/lucene/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/   (props changed)
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetField.java
    lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/AssociationFacetField.java
    lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java?rev=1555628&r1=1555627&r2=1555628&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/FacetField.java Sun Jan  5 20:53:23 2014
@@ -42,6 +42,10 @@ public class FacetField extends Field {
    *  {@code path}. */
   public FacetField(String dim, String... path) {
     super("dummy", TYPE);
+    verifyLabel(dim);
+    for(String label : path) {
+      verifyLabel(label);
+    }
     this.dim = dim;
     if (path.length == 0) {
       throw new IllegalArgumentException("path must have at least one element");
@@ -53,4 +57,13 @@ public class FacetField extends Field {
   public String toString() {
     return "FacetField(dim=" + dim + " path=" + Arrays.toString(path) + ")";
   }
+
+  /** Verifies the label is not null or empty string.
+   * 
+   *  @lucene.internal */
+  public static void verifyLabel(String label) {
+    if (label == null || label.isEmpty()) {
+      throw new IllegalArgumentException("empty or null components not allowed; got: " + label);
+    }
+  }
 }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetField.java?rev=1555628&r1=1555627&r2=1555628&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetField.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/sortedset/SortedSetDocValuesFacetField.java Sun Jan  5 20:53:23 2014
@@ -19,6 +19,7 @@ package org.apache.lucene.facet.sortedse
 
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
+import org.apache.lucene.facet.FacetField;
 
 /** Add an instance of this to your Document for every facet
  *  label to be indexed via SortedSetDocValues. */
@@ -40,6 +41,8 @@ public class SortedSetDocValuesFacetFiel
   /** Sole constructor. */
   public SortedSetDocValuesFacetField(String dim, String label) {
     super("dummy", TYPE);
+    FacetField.verifyLabel(label);
+    FacetField.verifyLabel(dim);
     this.dim = dim;
     this.label = label;
   }

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/AssociationFacetField.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/AssociationFacetField.java?rev=1555628&r1=1555627&r2=1555628&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/AssociationFacetField.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/java/org/apache/lucene/facet/taxonomy/AssociationFacetField.java Sun Jan  5 20:53:23 2014
@@ -22,6 +22,7 @@ import java.util.Arrays;
 import org.apache.lucene.document.Document; // javadocs
 import org.apache.lucene.document.Field;
 import org.apache.lucene.document.FieldType;
+import org.apache.lucene.facet.FacetField;
 import org.apache.lucene.facet.Facets;
 import org.apache.lucene.util.BytesRef;
 
@@ -56,6 +57,10 @@ public class AssociationFacetField exten
    *  association */
   public AssociationFacetField(BytesRef assoc, String dim, String... path) {
     super("dummy", TYPE);
+    FacetField.verifyLabel(dim);
+    for(String label : path) {
+      FacetField.verifyLabel(label);
+    }
     this.dim = dim;
     this.assoc = assoc;
     if (path.length == 0) {

Modified: lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java?rev=1555628&r1=1555627&r2=1555628&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java (original)
+++ lucene/dev/branches/branch_4x/lucene/facet/src/test/org/apache/lucene/facet/taxonomy/TestFacetLabel.java Sun Jan  5 20:53:23 2014
@@ -2,7 +2,10 @@ package org.apache.lucene.facet.taxonomy
 
 import java.util.Arrays;
 
+import org.apache.lucene.facet.FacetField;
 import org.apache.lucene.facet.FacetTestCase;
+import org.apache.lucene.facet.sortedset.SortedSetDocValuesFacetField;
+import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util._TestUtil;
 import org.junit.Test;
 
@@ -158,8 +161,104 @@ public class TestFacetLabel extends Face
         assertNotNull(new FacetLabel(components));
         fail("empty or null components should not be allowed: " + Arrays.toString(components));
       } catch (IllegalArgumentException e) {
-        // ok
+        // expected
       }
+      try {
+        new FacetField("dim", components);
+        fail("empty or null components should not be allowed: " + Arrays.toString(components));
+      } catch (IllegalArgumentException e) {
+        // expected
+      }
+      try {
+        new AssociationFacetField(new BytesRef(), "dim", components);
+        fail("empty or null components should not be allowed: " + Arrays.toString(components));
+      } catch (IllegalArgumentException e) {
+        // expected
+      }
+      try {
+        new IntAssociationFacetField(17, "dim", components);
+        fail("empty or null components should not be allowed: " + Arrays.toString(components));
+      } catch (IllegalArgumentException e) {
+        // expected
+      }
+      try {
+        new FloatAssociationFacetField(17.0f, "dim", components);
+        fail("empty or null components should not be allowed: " + Arrays.toString(components));
+      } catch (IllegalArgumentException e) {
+        // expected
+      }
+    }
+    try {
+      new FacetField(null, new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new FacetField("", new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new IntAssociationFacetField(17, null, new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new IntAssociationFacetField(17, "", new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new FloatAssociationFacetField(17.0f, null, new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new FloatAssociationFacetField(17.0f, "", new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new AssociationFacetField(new BytesRef(), null, new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new AssociationFacetField(new BytesRef(), "", new String[] {"abc"});
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new SortedSetDocValuesFacetField(null, "abc");
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new SortedSetDocValuesFacetField("", "abc");
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new SortedSetDocValuesFacetField("dim", null);
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
+    }
+    try {
+      new SortedSetDocValuesFacetField("dim", "");
+      fail("empty or null components should not be allowed");
+    } catch (IllegalArgumentException e) {
+      // expected
     }
   }