Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 499533290
  • Loading branch information
sjudd authored and glide-copybara-robot committed Jan 4, 2023
1 parent c9f76cc commit 0b54bf7
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 147 deletions.
13 changes: 5 additions & 8 deletions library/src/main/java/com/bumptech/glide/Glide.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,21 +137,18 @@ public static Glide get(@NonNull Context context) {
}

@GuardedBy("Glide.class")
@VisibleForTesting
static void checkAndInitializeGlide(
private static void checkAndInitializeGlide(
@NonNull Context context, @Nullable GeneratedAppGlideModule generatedAppGlideModule) {
// In the thread running initGlide(), one or more classes may call Glide.get(context).
// Without this check, those calls could trigger infinite recursion.
if (isInitializing) {
throw new IllegalStateException(
"Glide has been called recursively, this is probably an internal library error!");
"You cannot call Glide.get() in registerComponents(),"
+ " use the provided Glide instance instead");
}
isInitializing = true;
try {
initializeGlide(context, generatedAppGlideModule);
} finally {
isInitializing = false;
}
initializeGlide(context, generatedAppGlideModule);
isInitializing = false;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions library/src/main/java/com/bumptech/glide/RegistryFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,22 @@ static GlideSupplier<Registry> lazilyCreateAndInitializeRegistry(
final List<GlideModule> manifestModules,
@Nullable final AppGlideModule annotationGeneratedModule) {
return new GlideSupplier<Registry>() {
// Rely on callers using memoization if they want to avoid duplicate work, but
// rely on ourselves to verify that no recursive initialization occurs.
private boolean isInitializing;
private boolean isInitializingOrInitialized;

@Override
public Registry get() {
if (isInitializing) {
if (isInitializingOrInitialized) {
throw new IllegalStateException(
"Recursive Registry initialization! In your"
+ " AppGlideModule and LibraryGlideModules, Make sure you're using the provided "
+ "Registry rather calling glide.getRegistry()!");
}
isInitializingOrInitialized = true;

Trace.beginSection("Glide registry");
isInitializing = true;
try {
return createAndInitRegistry(glide, manifestModules, annotationGeneratedModule);
} finally {
isInitializing = false;
Trace.endSection();
}
}
Expand Down

This file was deleted.

This file was deleted.

0 comments on commit 0b54bf7

Please sign in to comment.