55import io .sentry .util .Objects ;
66import java .util .Set ;
77import java .util .concurrent .CopyOnWriteArraySet ;
8+
89import org .jetbrains .annotations .ApiStatus ;
910import org .jetbrains .annotations .NotNull ;
1011import org .jetbrains .annotations .Nullable ;
@@ -15,6 +16,8 @@ public final class SentryIntegrationPackageStorage {
1516 private static volatile @ Nullable SentryIntegrationPackageStorage INSTANCE ;
1617 private static final @ NotNull AutoClosableReentrantLock staticLock =
1718 new AutoClosableReentrantLock ();
19+ private static volatile @ Nullable Boolean mixedVersionsDetected = null ;
20+ private static final @ NotNull AutoClosableReentrantLock mixedVersionsLock = new AutoClosableReentrantLock ();
1821
1922 public static @ NotNull SentryIntegrationPackageStorage getInstance () {
2023 if (INSTANCE == null ) {
@@ -64,12 +67,42 @@ public void addPackage(final @NotNull String name, final @NotNull String version
6467
6568 SentryPackage newPackage = new SentryPackage (name , version );
6669 packages .add (newPackage );
70+ try (final @ NotNull ISentryLifecycleToken ignored = mixedVersionsLock .acquire ()) {
71+ mixedVersionsDetected = null ;
72+ }
6773 }
6874
6975 public @ NotNull Set <SentryPackage > getPackages () {
7076 return packages ;
7177 }
7278
79+ public boolean checkForMixedVersions (final @ NotNull ILogger logger ) {
80+ final @ Nullable Boolean mixedVersionsDetectedBefore = mixedVersionsDetected ;
81+ if (mixedVersionsDetectedBefore != null ) {
82+ return mixedVersionsDetectedBefore ;
83+ }
84+ try (final @ NotNull ISentryLifecycleToken ignored = mixedVersionsLock .acquire ()) {
85+ final @ NotNull String sdkVersion = BuildConfig .VERSION_NAME ;
86+ boolean mixedVersionsDetectedThisCheck = false ;
87+
88+ for (SentryPackage pkg : packages ) {
89+ if (pkg .getName ().startsWith ("maven:io.sentry:" ) && !sdkVersion .equalsIgnoreCase (pkg .getVersion ())) {
90+ logger .log (SentryLevel .ERROR , "The Sentry SDK has been configured with mixed versions. Expected %s to match core SDK version %s but was %s" , pkg .getName (), sdkVersion , pkg .getVersion ());
91+ mixedVersionsDetectedThisCheck = true ;
92+ }
93+ }
94+
95+ if (mixedVersionsDetectedThisCheck ) {
96+ logger .log (SentryLevel .ERROR , "^^^^^^^^^^^^^^^^^^^^^^^^^^^^" );
97+ logger .log (SentryLevel .ERROR , "^^^^^^^^^^^^^^^^^^^^^^^^^^^^" );
98+ logger .log (SentryLevel .ERROR , "^^^^^^^^^^^^^^^^^^^^^^^^^^^^" );
99+ logger .log (SentryLevel .ERROR , "^^^^^^^^^^^^^^^^^^^^^^^^^^^^" );
100+ }
101+ mixedVersionsDetected = mixedVersionsDetectedThisCheck ;
102+ return mixedVersionsDetectedThisCheck ;
103+ }
104+ }
105+
73106 @ TestOnly
74107 public void clearStorage () {
75108 integrations .clear ();
0 commit comments