Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy constructor of the Scope class doesn't copy contexts #1761

Closed
7 of 27 tasks
dmytrobabeshko opened this issue Oct 13, 2021 · 2 comments
Closed
7 of 27 tasks

Copy constructor of the Scope class doesn't copy contexts #1761

dmytrobabeshko opened this issue Oct 13, 2021 · 2 comments
Labels
Type: Bug Something isn't working

Comments

@dmytrobabeshko
Copy link

dmytrobabeshko commented Oct 13, 2021

Platform:

  • Android -> If yes, which Device API (and compileSdkVersion/targetSdkVersion/Build tools) version?
  • Java -> Liberica 11.0.12, level 11
  • Kotlin -> If yes, which Kotlin (and jvmTarget) version?
  • NDK -> If yes, which NDK/CMake version?
  • React-Native -> If yes, which version?
  • Timber -> If yes, which version?
  • Log4j2 -> If yes, which version?
  • Logback -> If yes, which version?
  • Spring -> If yes, which version?

IDE:

  • Android Studio -> If yes, which version?
  • IntelliJ -> Build #IU-213.4631.20, built on October 6, 2021
  • Other -> If yes, which one?

Build system:

  • Gradle -> 7.2
  • Buck -> If yes, which version?
  • Bazel -> If yes, which version?
  • Maven -> If yes, which version?
  • Other -> If yes, which one?

Android Gradle Plugin:

  • Yes -> If yes, which version?
  • No

Sentry Android Gradle Plugin:

  • Yes -> If yes, which version?
  • No

Proguard/R8:

  • Enabled
  • Disabled

Platform installed with:

  • JCenter
  • Bintray
  • Maven Central
  • Manually

The version of the SDK:
5.2.1


When clonnig Sentry.getCurrentHub() and setting it to the current hub in the new thread scope.contexts is not copied and always empty.

Example code:

private @NotNull Runnable copyContext(@NotNull Runnable runnable) {
    final IHub oldState = Sentry.getCurrentHub();
    final IHub newHub = Sentry.getCurrentHub().clone();

    return () -> {
        try {
            Sentry.setCurrentHub(newHub);
            runnable.run();
        } finally {
            Sentry.setCurrentHub(oldState);
        }
    };
}

Root cause:
Looks like this is because of the issue in the copy constructor of the Scope class.

this.contexts = new Contexts(contexts);

this.contexts and contexts are actually exactly the same this instance

image

Expected result:

  • scope.contexts is copied to the new hub while cloning
@marandaneto
Copy link
Contributor

@dmitrybabeshko thanks for raising, good catch, looks like it should be:

this.contexts = new Contexts(scope.contexts); instead.

@maciejwalkowiak mind having a look?

@maciejwalkowiak
Copy link
Contributor

Fixed in #1763

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants