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 a race condition in CtClassType#getClassFile3 #363

Merged
merged 1 commit into from Apr 25, 2021
Merged
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
25 changes: 19 additions & 6 deletions src/main/javassist/CtClassType.java
Expand Up @@ -179,24 +179,37 @@ public ClassFile getClassFile2() {
}

public ClassFile getClassFile3(boolean doCompress) {
// quick path - no locking
ClassFile cfile = classfile;
if (cfile != null)
return cfile;

if (doCompress)
classPool.compress();

if (rawClassfile != null) {
byte[] rcfile;
synchronized (this) {
// repeat under lock to make sure we get a consistent result (classfile might have been set by another thread)
cfile = classfile;
if (cfile != null)
return cfile;

rcfile = rawClassfile;
}

if (rcfile != null) {
final ClassFile cf;
try {
ClassFile cf = new ClassFile(new DataInputStream(
new ByteArrayInputStream(rawClassfile)));
rawClassfile = null;
getCount = GET_THRESHOLD;
return setClassFile(cf);
cf = new ClassFile(new DataInputStream(new ByteArrayInputStream(rcfile)));
}
catch (IOException e) {
throw new RuntimeException(e.toString(), e);
}
getCount = GET_THRESHOLD;
synchronized (this) {
rawClassfile = null;
return setClassFile(cf);
}
}

InputStream fin = null;
Expand Down