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

[Android] removeSource no longer (6.0.0+) safe when source does not exist #11779

Closed
rm3dbeckers opened this issue Apr 26, 2018 · 1 comment
Closed
Labels
Android Mapbox Maps SDK for Android

Comments

@rm3dbeckers
Copy link

Platform: Android
Mapbox SDK version: 6.0.1

Steps to trigger behavior

  1. call MapboxMap.removeSource(String sourceID) with a sourceID that has not been added.

Expected behavior

The call should succeed and return null.

Actual behavior

The call throws an NPE.

NativeMapView.java will perform the following:

  @Nullable
  public Source removeSource(@NonNull String sourceId) {
    if (isDestroyedOn("removeSource")) {
      return null;
    }
    Source source = getSource(sourceId);
    return removeSource(source);
  }

getSource(sourceId) will correctly return a null Source but the following removeSource(source) call expects a non-null Source and causes an NPE when trying to get the NativePtr:

  public Source removeSource(@NonNull Source source) {
    if (isDestroyedOn("removeSource")) {
      return null;
    }
    nativeRemoveSource(source, source.getNativePtr());
    return source;
  }

This worked correctly on 5.5.2.

@fabian-guerra fabian-guerra added the Android Mapbox Maps SDK for Android label Apr 26, 2018
@LukasPaczos
Copy link
Contributor

Good catch, thanks @rm3dbeckers.

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

No branches or pull requests

3 participants