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 2016/01/29 21:39:46 UTC
lucene-solr git commit: catch invalide usage of XXXPoint APIs,
when dimensions are mismatched
Repository: lucene-solr
Updated Branches:
refs/heads/master 07c9b2bda -> 5d5b082e6
catch invalide usage of XXXPoint APIs, when dimensions are mismatched
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/5d5b082e
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/5d5b082e
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/5d5b082e
Branch: refs/heads/master
Commit: 5d5b082e6d68413c274c8259c235c2d56b14a760
Parents: 07c9b2b
Author: Mike McCandless <mi...@apache.org>
Authored: Fri Jan 29 15:39:06 2016 -0500
Committer: Mike McCandless <mi...@apache.org>
Committed: Fri Jan 29 15:39:06 2016 -0500
----------------------------------------------------------------------
.../org/apache/lucene/document/DoublePoint.java | 6 ++
.../org/apache/lucene/document/FloatPoint.java | 6 ++
.../org/apache/lucene/document/IntPoint.java | 6 ++
.../org/apache/lucene/document/LongPoint.java | 6 ++
.../apache/lucene/index/TestPointValues.java | 71 ++++++++++++++++++++
5 files changed, 95 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d5b082e/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java b/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
index a7a63e0..a12a0c9 100644
--- a/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/DoublePoint.java
@@ -42,6 +42,9 @@ public final class DoublePoint extends Field {
/** Change the values of this field */
public void setDoubleValues(double... point) {
+ if (type.pointDimensionCount() != point.length) {
+ throw new IllegalArgumentException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot change to (incoming) " + point.length + " dimensions");
+ }
fieldsData = pack(point);
}
@@ -52,6 +55,9 @@ public final class DoublePoint extends Field {
@Override
public Number numericValue() {
+ if (type.pointDimensionCount() != 1) {
+ throw new IllegalStateException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot convert to a single numeric value");
+ }
BytesRef bytes = (BytesRef) fieldsData;
assert bytes.length == RamUsageEstimator.NUM_BYTES_LONG;
return NumericUtils.sortableLongToDouble(NumericUtils.bytesToLongDirect(bytes.bytes, bytes.offset));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d5b082e/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java b/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
index a023a4a..00766ef 100644
--- a/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/FloatPoint.java
@@ -42,6 +42,9 @@ public final class FloatPoint extends Field {
/** Change the values of this field */
public void setFloatValues(float... point) {
+ if (type.pointDimensionCount() != point.length) {
+ throw new IllegalArgumentException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot change to (incoming) " + point.length + " dimensions");
+ }
fieldsData = pack(point);
}
@@ -52,6 +55,9 @@ public final class FloatPoint extends Field {
@Override
public Number numericValue() {
+ if (type.pointDimensionCount() != 1) {
+ throw new IllegalStateException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot convert to a single numeric value");
+ }
BytesRef bytes = (BytesRef) fieldsData;
assert bytes.length == RamUsageEstimator.NUM_BYTES_INT;
return NumericUtils.sortableIntToFloat(NumericUtils.bytesToIntDirect(bytes.bytes, bytes.offset));
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d5b082e/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/IntPoint.java b/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
index 28f6a55..ef48706 100644
--- a/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/IntPoint.java
@@ -42,6 +42,9 @@ public final class IntPoint extends Field {
/** Change the values of this field */
public void setIntValues(int... point) {
+ if (type.pointDimensionCount() != point.length) {
+ throw new IllegalArgumentException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot change to (incoming) " + point.length + " dimensions");
+ }
fieldsData = pack(point);
}
@@ -52,6 +55,9 @@ public final class IntPoint extends Field {
@Override
public Number numericValue() {
+ if (type.pointDimensionCount() != 1) {
+ throw new IllegalStateException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot convert to a single numeric value");
+ }
BytesRef bytes = (BytesRef) fieldsData;
assert bytes.length == RamUsageEstimator.NUM_BYTES_INT;
return NumericUtils.bytesToInt(bytes.bytes, bytes.offset);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d5b082e/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/document/LongPoint.java b/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
index 23fddb2..15810d1 100644
--- a/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
+++ b/lucene/core/src/java/org/apache/lucene/document/LongPoint.java
@@ -42,6 +42,9 @@ public final class LongPoint extends Field {
/** Change the values of this field */
public void setLongValues(long... point) {
+ if (type.pointDimensionCount() != point.length) {
+ throw new IllegalArgumentException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot change to (incoming) " + point.length + " dimensions");
+ }
fieldsData = pack(point);
}
@@ -52,6 +55,9 @@ public final class LongPoint extends Field {
@Override
public Number numericValue() {
+ if (type.pointDimensionCount() != 1) {
+ throw new IllegalStateException("this field (name=" + name + ") uses " + type.pointDimensionCount() + " dimensions; cannot convert to a single numeric value");
+ }
BytesRef bytes = (BytesRef) fieldsData;
assert bytes.length == RamUsageEstimator.NUM_BYTES_LONG;
return NumericUtils.bytesToLong(bytes.bytes, bytes.offset);
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/5d5b082e/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
index 738109e..ff5fdf8 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestPointValues.java
@@ -21,8 +21,11 @@ import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.BinaryPoint;
import org.apache.lucene.document.Document;
+import org.apache.lucene.document.DoublePoint;
import org.apache.lucene.document.Field;
+import org.apache.lucene.document.FloatPoint;
import org.apache.lucene.document.IntPoint;
+import org.apache.lucene.document.LongPoint;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
@@ -435,4 +438,72 @@ public class TestPointValues extends LuceneTestCase {
w.close();
dir.close();
}
+
+ public void testInvalidIntPointUsage() throws Exception {
+ IntPoint field = new IntPoint("field", 17, 42);
+ try {
+ field.setIntValue(14);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // good
+ }
+
+ try {
+ field.numericValue();
+ fail("did not hit exception");
+ } catch (IllegalStateException ise) {
+ // good
+ }
+ }
+
+ public void testInvalidLongPointUsage() throws Exception {
+ LongPoint field = new LongPoint("field", 17, 42);
+ try {
+ field.setLongValue(14);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // good
+ }
+
+ try {
+ field.numericValue();
+ fail("did not hit exception");
+ } catch (IllegalStateException ise) {
+ // good
+ }
+ }
+
+ public void testInvalidFloatPointUsage() throws Exception {
+ FloatPoint field = new FloatPoint("field", 17, 42);
+ try {
+ field.setFloatValue(14);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // good
+ }
+
+ try {
+ field.numericValue();
+ fail("did not hit exception");
+ } catch (IllegalStateException ise) {
+ // good
+ }
+ }
+
+ public void testInvalidDoublePointUsage() throws Exception {
+ DoublePoint field = new DoublePoint("field", 17, 42);
+ try {
+ field.setDoubleValue(14);
+ fail("did not hit exception");
+ } catch (IllegalArgumentException iae) {
+ // good
+ }
+
+ try {
+ field.numericValue();
+ fail("did not hit exception");
+ } catch (IllegalStateException ise) {
+ // good
+ }
+ }
}