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

getFilter crash when using within on JSONArray #303

Closed
chloekraw opened this issue Apr 1, 2020 · 5 comments · Fixed by #305
Closed

getFilter crash when using within on JSONArray #303

chloekraw opened this issue Apr 1, 2020 · 5 comments · Fixed by #305
Assignees

Comments

@chloekraw
Copy link
Contributor

Logcat:

java.lang.IllegalStateException
        at com.google.gson.JsonArray.getAsString(JsonArray.java:226)
        at com.mapbox.mapboxsdk.style.expressions.Expression$Converter.convert(Expression.java:4747)
        at com.mapbox.mapboxsdk.style.expressions.Expression$Converter.convert(Expression.java:4780)
        at com.mapbox.mapboxsdk.style.expressions.Expression$Converter.convert(Expression.java:4788)
        at com.mapbox.mapboxsdk.style.expressions.Expression$Converter.convert(Expression.java:4766)
        at com.mapbox.mapboxsdk.style.expressions.Expression$Converter.convert(Expression.java:4780)
        at com.mapbox.mapboxsdk.style.layers.SymbolLayer.getFilter(SymbolLayer.java:128)

Implementation:

     symbolLayer.setFilter(Expression.within(customPolygon));
     symbolLayer.getFilter()); 

Snippet of function that generates customPolygon:

...
        List<List<Point>> pointLists = new ArrayList<>();
        pointLists.add(points);
        return Polygon.fromLngLats(pointLists);

cc @mapbox/maps-android

@chloekraw
Copy link
Contributor Author

chloekraw commented Apr 1, 2020

@Chaoba has a possible workaround we could implement to unblock the release in the short term, but we've escalated an investigation upstream first to see if there is a better long-term solution.

@1ec5
Copy link
Contributor

1ec5 commented Apr 1, 2020

This issue is on the iOS project board with the following note:

Try to reproduce this Android issue with setting a filter using within and a JSONArray where the root cause is upstream

At a glance, I don’t see how this issue could be relevant to iOS/macOS, because the crash relates to Android-specific conversion code that uses GSON, an Android-specific library.

I think the analogous conversion code on iOS/macOS is adequately exercised by these unit tests, which pass on master.

@tobrun
Copy link
Member

tobrun commented Apr 1, 2020

Glad to hear @1ec5 that this is not an issue for you.

For us, the issue comes from setting the following:

["within", {"json": "{"type":"Polygon","coordinates":[[[-77.0686734,38.9046766],[-77.0623326,38.9047934],[-77.0623434,38.9064632],[-77.0629013,38.9072063],[-77.0636415,38.9068473],[-77.063266,38.9063714],[-77.0632124,38.9055616],[-77.0691454,38.9054363],[-77.069124,38.9046682],[-77.0686734,38.9046766]]]}", "type": "Polygon"}]

But getting back :

["within",{"coordinates":[[[-77.0686734,38.9046766],[-77.0623326,38.9047934],[-77.0623434,38.9064632],[-77.0629013,38.9072063],[-77.0636415,38.9068473],[-77.063266,38.9063714],[-77.0632124,38.9055616],[-77.0691454,38.9054363],[-77.069124,38.9046682],[-77.0686734,38.9046766]]],"type":"Polygon"}]

@Chaoba could you look into why we are converting our input to the first block in mapbox-java? This doesn't look like valid json to me.

@Chaoba
Copy link
Contributor

Chaoba commented Apr 1, 2020

The reason why we need this key "json" is that we need to convert Object(map in android) to a Geojon object in this pr
mapbox/mapbox-gl-native#16243

As @zmiao 's response in https://github.com/mapbox/mapbox-gl-native-team/issues/273#issuecomment-607136085 this issue should not be related with gl-native.

@tobrun
Copy link
Member

tobrun commented Apr 1, 2020

let's move forward with the hack in the android conversion system, for v10.0.0 of the SDK we will support a different conversion system that wouldn't require any workarounds.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants