mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
475 stars 133 forks source link

ClassCastException when parsing a match expressing using fromRaw #2032

Closed mattijsf closed 1 year ago

mattijsf commented 1 year ago

Environment

Observed behavior and steps to reproduce

Parsing a match expressing using fromRaw containing numeric label will causing a ClassCastException

Expression: ["match",["get","data_property"],[0],true,false]

Example:

com.mapbox.maps.extension.style.expressions.generated.Expression.fromRaw("[\"match\",[\"get\",\"data_property\"],[0],true,false]")

Exception:

java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.String
    at com.mapbox.maps.extension.style.utils.TypeUtilsKt.unwrapToExpression(TypeUtils.kt:92)
    at com.mapbox.maps.extension.style.utils.TypeUtilsKt.unwrapToExpression(TypeUtils.kt:250)
    at com.mapbox.maps.extension.style.utils.TypeUtilsKt.unwrapToExpression(TypeUtils.kt:250)
    at com.mapbox.maps.extension.style.expressions.generated.Expression$Companion.fromRaw(Expression.kt:28)
    at com.mapbox.maps.extension.style.expressions.generated.Expression.fromRaw

I'm aware that this expression can be written more optimal using an equal expression but this expression was generated by Mapbox Studio somehow and was causing a crash in our app when processing / parsing a mapbox studio generated style.

Also, changing the [0] into ["0"] succeeds but that doesn't change the fact that the Expression parser should be able to parse the above expression.

Expected behavior

Expression gets parsed normally with the numeric array

mattijsf commented 1 year ago

As a temporary workaround we use ["==", ["get", "data_property"], 0]. But like I said, in some cases Mapbox Studio's expression builder is constructing a match expression for simple numeric equality checks which cannot be parsed by Expression.fromRaw

pengdev commented 1 year ago

Thanks for the report @mattijsf , the root cause is identified and we will provide a fix in the coming releases.