Skip to content

Commit

Permalink
Merge pull request #363 from michalkurka/master
Browse files Browse the repository at this point in the history
Fix a race condition in CtClassType#getClassFile3
  • Loading branch information
chibash committed Apr 25, 2021
2 parents 6786fd5 + 64e1535 commit b4cb5cb
Showing 1 changed file with 19 additions and 6 deletions.
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

0 comments on commit b4cb5cb

Please sign in to comment.