Skip to content

Fix a bug in ConstructorCache when classes are GC'ed but not removed from cache #6186

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

Merged
merged 3 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AWSSDKforJavaV2-a136845.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java V2",
"contributor": "",
"description": "Fix a bug in ConstructorCache when classes are GC'ed but not removed from cache"
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,17 @@ private Optional<Class<?>> getClass(String className) {
return Optional.empty();
}
});
return classRef.map(WeakReference::get);

// if the WeakReference to the class has been garbage collected, remove it from the cache and try again
if (classRef.isPresent()) {
Class<?> clazz = classRef.get().get();
if (clazz != null) {
return Optional.of(clazz);
}
classesByClassLoader.remove(classLoader);
return getClass(className);
}
return Optional.empty();
}

/**
Expand Down
Loading