Merge pull request #12913 from xuzha/xu-exception

Validate class before cast.
This commit is contained in:
Adrien Grand 2015-08-17 09:38:59 +02:00
commit 1f2345db34
1 changed files with 12 additions and 0 deletions

View File

@ -156,6 +156,12 @@ public class AggregationContext {
} }
private ValuesSource.Numeric numericField(ValuesSourceConfig<?> config) throws IOException { private ValuesSource.Numeric numericField(ValuesSourceConfig<?> config) throws IOException {
if (!(config.fieldContext.indexFieldData() instanceof IndexNumericFieldData)) {
throw new IllegalArgumentException("Expected numeric type on field [" + config.fieldContext.field() +
"], but got [" + config.fieldContext.fieldType().typeName() + "]");
}
ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData) config.fieldContext.indexFieldData()); ValuesSource.Numeric dataSource = new ValuesSource.Numeric.FieldData((IndexNumericFieldData) config.fieldContext.indexFieldData());
if (config.script != null) { if (config.script != null) {
dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script); dataSource = new ValuesSource.Numeric.WithScript(dataSource, config.script);
@ -184,6 +190,12 @@ public class AggregationContext {
} }
private ValuesSource.GeoPoint geoPointField(ValuesSourceConfig<?> config) throws IOException { private ValuesSource.GeoPoint geoPointField(ValuesSourceConfig<?> config) throws IOException {
if (!(config.fieldContext.indexFieldData() instanceof IndexGeoPointFieldData)) {
throw new IllegalArgumentException("Expected geo_point type on field [" + config.fieldContext.field() +
"], but got [" + config.fieldContext.fieldType().typeName() + "]");
}
return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) config.fieldContext.indexFieldData()); return new ValuesSource.GeoPoint.Fielddata((IndexGeoPointFieldData) config.fieldContext.indexFieldData());
} }