summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorTobrun <tobrun@mapbox.com>2018-04-04 11:33:37 +0200
committerŁukasz Paczos <lukasz.paczos@mapbox.com>2018-04-04 11:33:37 +0200
commit1730756e87550b6ca313051c9b87806dac561b18 (patch)
tree7e0b15ba073ec3020d931e40458eafb83b9ee85d /platform
parentddd8fb7a051732cbbfa29c7350f2dc0a06df8893 (diff)
downloadqtlocation-mapboxgl-1730756e87550b6ca313051c9b87806dac561b18.tar.gz
[android] - throw illegal argument exception when attempting to convert an PropertyValue as an expression literal (#11572)
Diffstat (limited to 'platform')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java5
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java10
2 files changed, 14 insertions, 1 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
index efb2660da0..79eb2ab32a 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/style/expressions/Expression.java
@@ -9,6 +9,7 @@ import com.google.gson.JsonArray;
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;
@@ -1735,7 +1736,9 @@ public class Expression {
*/
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();
diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
index 22c25fd0df..9d4caa1fef 100644
--- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/style/expressions/ExpressionTest.java
@@ -73,6 +73,7 @@ import static com.mapbox.mapboxsdk.style.expressions.Expression.typeOf;
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;
@@ -1095,4 +1096,13 @@ public class ExpressionTest {
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();
+ }
} \ No newline at end of file