Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Throw exception when converting PropertyValue with an expression #11572

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gson.JsonElement;
import com.google.gson.JsonPrimitive;
import com.mapbox.mapboxsdk.style.layers.PropertyFactory;
import com.mapbox.mapboxsdk.style.layers.PropertyValue;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -1735,7 +1736,9 @@ public Object[] toArray() {
*/
private Object toValue(ExpressionLiteral expressionValue) {
Object value = expressionValue.toValue();
if (value instanceof Expression.ExpressionLiteral) {
if (value instanceof PropertyValue) {
throw new IllegalArgumentException("PropertyValue are not allowed as an expression literal, use value instead.");
} else if (value instanceof Expression.ExpressionLiteral) {
return toValue((ExpressionLiteral) value);
} else if (value instanceof Expression) {
return ((Expression) value).toArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import static com.mapbox.mapboxsdk.style.expressions.Expression.upcase;
import static com.mapbox.mapboxsdk.style.expressions.Expression.var;
import static com.mapbox.mapboxsdk.style.expressions.Expression.zoom;
import static com.mapbox.mapboxsdk.style.layers.PropertyFactory.lineOpacity;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

Expand Down Expand Up @@ -1095,4 +1096,13 @@ public void testColorConversion() {
assertTrue("expression should match", Arrays.deepEquals(expected, greenColor.toArray()));
}

@Test(expected = IllegalArgumentException.class)
public void testThrowIllegalArgumentExceptionForPropertyValueLiteral() {
Expression expression = interpolate(exponential(1f), zoom(),
stop(17f, lineOpacity(1f)),
stop(16.5f, lineOpacity(0.5f)),
stop(16f, lineOpacity(0f))
);
expression.toArray();
}
}