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

[android] returning null instead of the Source object in the MapboxMap#removeSource when it fails #13428

Merged
merged 1 commit into from
Dec 7, 2018

Conversation

osana
Copy link
Contributor

@osana osana commented Nov 20, 2018

closes #12526

@osana osana added the Android Mapbox Maps SDK for Android label Nov 20, 2018
@osana osana force-pushed the osana-return-fromRemoveSource branch 2 times, most recently from d2c060e to 881e405 Compare November 21, 2018 03:49
Copy link
Member

@tobrun tobrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for picking this up @osana. Seeing that we return the source object to the user instead of true/false feels a bit strange to me. Take for example following codeblock:

geoJsonSource = mapboxMap.removeSource(geoJsonSource);
if(geoJsonSource == null){
 // we couldn’t remove source
}

I think it makes more sense following the core setup to return true or false on the public api. If we would do this, we should also need to fix removeLayer as well.

thoughts @mapbox/maps-android ?

@LukasPaczos
Copy link
Contributor

I agree with @tobrun, remove methods might be more readable if they return boolean values indicating whether removal has been successful. Users can always fetch the layer/source before removal with get methods which should cover current use cases.

@osana osana force-pushed the osana-return-fromRemoveSource branch 2 times, most recently from 86be772 to b95dd52 Compare November 21, 2018 15:31
@osana
Copy link
Contributor Author

osana commented Nov 21, 2018

@tobrun @LukasPaczos Do you think it makes sense to change removeLayer return value
in this PR?

@LukasPaczos
Copy link
Contributor

Sure, shouldn't be an issue.

@LukasPaczos LukasPaczos added the SEMVER-MAJOR Requires a major release according to Semantic Versioning rules label Nov 21, 2018
@LukasPaczos LukasPaczos added this to the android-v7.0.0-iowaska milestone Nov 21, 2018
@osana osana force-pushed the osana-return-fromRemoveSource branch 3 times, most recently from 618f45f to 3281250 Compare November 28, 2018 05:38
}

/**
* Remove with wrapper object id. Ownership is transferred back to the wrapper
*/
void NativeMapView::removeLayer(JNIEnv&, jlong layerPtr) {
jni::jboolean NativeMapView::removeLayer(JNIEnv&, jlong layerPtr) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other remove method besides this one drops the reference to the layer, so the one kept in Java is probably going to become invalid. In order to make our intended logic possible, that a user fetches the layer with getLayer (or just keeps the reference from the start) and can keep after it's removed from the map (successfully or not), we need to keep the reference valid.

@osana
Copy link
Contributor Author

osana commented Nov 29, 2018

@tobrun @LukasPaczos Capturing offline conversation of what needs to happen in this PR

  1. MapboxMap has three removeLayer methods. At the moment two of them invalidate existing jav areferences to the removed layer.
    * Removes the layer. Any references to the layer become invalid and should not be used anymore

    * Removes the layer. Any other references to the layer become invalid and should not be used anymore

We need the above two methods keep the reference alive ( transfer ownership from native to java peer) as it is done in

* Removes the layer. The reference is re-usable after this and can be re-added

TODO: javadoc update & native_map_view.cpp change

  1. Add test to verify the above is working, ie the reference to Layer in java is still valid after the Layer was removed

  2. MapboxMap has two methods to removeSource. They result in the same native method call.
    But Javadoc does not reflect that

* Removes the source. Any references to the source become invalid and should not be used anymore

in both cases the reference should be kept alive

  1. Add test to verify 2 is working, ie the reference to Source is still valid in java after the Source was removed

@osana osana force-pushed the osana-return-fromRemoveSource branch 3 times, most recently from 9506127 to bcc671c Compare November 30, 2018 20:46
jni::Local<jni::Object<Layer>> layerObj =
LayerManagerAndroid::get()->createJavaLayerPeer(env, *map, std::move(coreLayer));
mbgl::android::Layer *layer = reinterpret_cast<mbgl::android::Layer *>(layerObj.get());
layer->setLayer(std::move(coreLayer));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobrun could you ask someone with more knowledge of c++ how this should be done . Lines 846 -848 are not correct.

@osana osana force-pushed the osana-return-fromRemoveSource branch from bcc671c to de18ed8 Compare December 5, 2018 18:58
Copy link
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be great to add test covering a scenario when removal fails. Otherwise LGTM 👍

}
return nativeRemoveLayerAt(index);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: new line

@tobrun tobrun added the beta blocker Blocks the next beta release label Dec 7, 2018
@osana osana force-pushed the osana-return-fromRemoveSource branch 2 times, most recently from 809d460 to 4630831 Compare December 7, 2018 15:21
@osana osana force-pushed the osana-return-fromRemoveSource branch from 4630831 to 6c23514 Compare December 7, 2018 15:22
Copy link
Contributor

@LukasPaczos LukasPaczos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@osana osana merged commit ea775ae into master Dec 7, 2018
@osana osana deleted the osana-return-fromRemoveSource branch December 7, 2018 18:10
@osana osana removed the beta blocker Blocks the next beta release label Dec 7, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android SEMVER-MAJOR Requires a major release according to Semantic Versioning rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Removing source processed by the layer
3 participants