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

Commit

Permalink
[android] - throw illegal argument exception when attempting to conve…
Browse files Browse the repository at this point in the history
…rt an PropertyValue as an expression literal (#11572)
  • Loading branch information
tobrun authored and Łukasz Paczos committed Apr 4, 2018
1 parent ddd8fb7 commit 1730756
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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();
}
}

0 comments on commit 1730756

Please sign in to comment.