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

Fix TypeCache dead lock #902

Merged
merged 1 commit into from Jan 23, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.gradle
Expand Up @@ -45,8 +45,8 @@ apply from: 'gradle/root/version.gradle'
apply from: "gradle/java-library.gradle"

dependencies {
compile 'net.bytebuddy:byte-buddy:1.6.4'
compile 'net.bytebuddy:byte-buddy-agent:1.6.4'
compile 'net.bytebuddy:byte-buddy:1.6.5'
compile 'net.bytebuddy:byte-buddy-agent:1.6.5'

provided "junit:junit:4.12", "org.hamcrest:hamcrest-core:1.3"
compile "org.objenesis:objenesis:2.5"
Expand Down
Expand Up @@ -13,6 +13,8 @@

class TypeCachingBytecodeGenerator extends ReferenceQueue<ClassLoader> implements BytecodeGenerator {

private final Object BOOTSTRAP_LOCK = new Object();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this field intended to be constant? If not, it should have lower case name.

Copy link
Member Author

@raphw raphw Jan 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is true, this should be lower case but yes, it should be an instance constant.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However this lock should not be static.


private final BytecodeGenerator bytecodeGenerator;

private final TypeCache<SerializationFeatureKey> typeCache;
Expand All @@ -26,15 +28,15 @@ public TypeCachingBytecodeGenerator(BytecodeGenerator bytecodeGenerator, boolean
@Override
public <T> Class<T> mockClass(final MockFeatures<T> params) {
try {

return (Class<T>) typeCache.findOrInsert(params.mockedType.getClassLoader(),
new SerializationFeatureKey(params.mockedType, params.interfaces, params.serializableMode),
new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return bytecodeGenerator.mockClass(params);
}
}, params.mockedType);
ClassLoader classLoader = params.mockedType.getClassLoader();
return (Class<T>) typeCache.findOrInsert(classLoader,
new SerializationFeatureKey(params.mockedType, params.interfaces, params.serializableMode),
new Callable<Class<?>>() {
@Override
public Class<?> call() throws Exception {
return bytecodeGenerator.mockClass(params);
}
}, classLoader == null ? BOOTSTRAP_LOCK : classLoader);
} catch (IllegalArgumentException exception) {
Throwable cause = exception.getCause();
if (cause instanceof RuntimeException) {
Expand Down
2 changes: 1 addition & 1 deletion subprojects/android/android.gradle
Expand Up @@ -11,7 +11,7 @@ apply from: "$rootDir/gradle/java-library.gradle"

dependencies {
compile project.rootProject
compile "net.bytebuddy:byte-buddy-android:1.6.4"
compile "net.bytebuddy:byte-buddy-android:1.6.5"
}

apply from: "$rootDir/gradle/publishable-java-library.gradle"
Expand Down