Skip to content

Apache Lucene open-source search software

LUCENE-4413 Standardize on throwing UnsupportedOperationException for a shape the strategy doesn't support. Document it.

David Wayne Smileya7979cf3f72b
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java
index c589d829954..2fb173518fc 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/SpatialStrategy.java
@@ -96,6 +96,7 @@ public abstract class SpatialStrategy {
* since it doesn't use it.
*
* @return Not null nor will it have null elements.
+ * @throws UnsupportedOperationException if given a shape incompatible with the strategy
*/
public abstract Field[] createIndexableFields(Shape shape);
@@ -111,6 +112,10 @@ public abstract class SpatialStrategy {
* and {@link Shape} from the supplied {@code args}.
* The default implementation is
* <pre>return new ConstantScoreQuery(makeFilter(args));</pre>
+ *
+ * @throws UnsupportedOperationException If the strategy does not support the shape in {@code args}
+ * @throws org.apache.lucene.spatial.query.UnsupportedSpatialOperation If the strategy does not support the {@link
+ * org.apache.lucene.spatial.query.SpatialOperation} in {@code args}.
*/
public ConstantScoreQuery makeQuery(SpatialArgs args) {
return new ConstantScoreQuery(makeFilter(args));
@@ -124,6 +129,10 @@ public abstract class SpatialStrategy {
* {@link #makeQuery(org.apache.lucene.spatial.query.SpatialArgs)}
* then this method could be simply:
* <pre>return new QueryWrapperFilter(makeQuery(args).getQuery());</pre>
+ *
+ * @throws UnsupportedOperationException If the strategy does not support the shape in {@code args}
+ * @throws org.apache.lucene.spatial.query.UnsupportedSpatialOperation If the strategy does not support the {@link
+ * org.apache.lucene.spatial.query.SpatialOperation} in {@code args}.
*/
public abstract Filter makeFilter(SpatialArgs args);
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
index 356b24bca40..e723890efc4 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/bbox/BBoxStrategy.java
@@ -95,7 +95,7 @@ public class BBoxStrategy extends SpatialStrategy {
public Field[] createIndexableFields(Shape shape) {
if (shape instanceof Rectangle)
return createIndexableFields((Rectangle)shape);
- throw new IllegalArgumentException("Can only index Rectangle, not " + shape);
+ throw new UnsupportedOperationException("Can only index Rectangle, not " + shape);
}
public Field[] createIndexableFields(Rectangle bbox) {
@@ -150,7 +150,7 @@ public class BBoxStrategy extends SpatialStrategy {
private Query makeSpatialQuery(SpatialArgs args) {
Shape shape = args.getShape();
if (!(shape instanceof Rectangle))
- throw new IllegalArgumentException("Can only query by Rectangle, not " + shape);
+ throw new UnsupportedOperationException("Can only query by Rectangle, not " + shape);
Rectangle bbox = (Rectangle) shape;
Query spatial = null;
diff --git a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
index 0e8253dd795..1a1fa648857 100644
--- a/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
+++ b/lucene/spatial/src/java/org/apache/lucene/spatial/vector/TwoDoublesStrategy.java
@@ -18,7 +18,6 @@ package org.apache.lucene.spatial.vector;
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.exception.InvalidShapeException;
import com.spatial4j.core.shape.Circle;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Rectangle;
@@ -90,7 +89,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
public Field[] createIndexableFields(Shape shape) {
if (shape instanceof Point)
return createIndexableFields((Point) shape);
- throw new IllegalArgumentException("Can only index Point, not " + shape);
+ throw new UnsupportedOperationException("Can only index Point, not " + shape);
}
/** @see #createIndexableFields(com.spatial4j.core.shape.Shape) */
@@ -139,7 +138,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
circle.getRadius() );
return new ConstantScoreQuery(vsf);
} else {
- throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
+ throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " +
"found [" + shape.getClass() + "]");//TODO
}
}
@@ -149,7 +148,7 @@ public class TwoDoublesStrategy extends SpatialStrategy {
// For starters, just limit the bbox
Shape shape = args.getShape();
if (!(shape instanceof Rectangle || shape instanceof Circle)) {
- throw new InvalidShapeException("Only Rectangles and Circles are currently supported, " +
+ throw new UnsupportedOperationException("Only Rectangles and Circles are currently supported, " +
"found [" + shape.getClass() + "]");//TODO
}
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java b/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
index ff8a54c9275..9f1fb5f68fc 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/vector/TestTwoDoublesStrategy.java
@@ -18,7 +18,6 @@ package org.apache.lucene.spatial.vector;
*/
import com.spatial4j.core.context.SpatialContext;
-import com.spatial4j.core.exception.InvalidShapeException;
import com.spatial4j.core.shape.Circle;
import com.spatial4j.core.shape.Point;
import org.apache.lucene.search.Query;
@@ -50,7 +49,7 @@ public class TestTwoDoublesStrategy extends StrategyTestCase {
assertNotNull(query);
}
- @Test(expected = InvalidShapeException.class)
+ @Test(expected = UnsupportedOperationException.class)
public void testInvalidQueryShape() {
Point point = ctx.makePoint(0, 0);
SpatialArgs args = new SpatialArgs(SpatialOperation.Intersects, point);