Skip to content

Commit 3f1d7db

Browse files
authored
[java] Fix race condition in ClassStub for inner classes (pmd#5583)
2 parents e9a0da1 + 5824d59 commit 3f1d7db

File tree

1 file changed

+11
-5
lines changed
  • pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm

1 file changed

+11
-5
lines changed

pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/internal/asm/ClassStub.java

+11-5
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,17 @@ in InnerClasses (resp. ClassInfo), the rest are available in both)
227227
}
228228
this.accessFlags = myAccess | accessFlags;
229229

230-
if ((accessFlags & Opcodes.ACC_ENUM) != 0) {
231-
this.enumConstants = new ArrayList<>();
232-
}
233-
if ((accessFlags & Opcodes.ACC_RECORD) != 0) {
234-
this.recordComponents = new ArrayList<>();
230+
// setModifiers is called multiple times: once from ClassFile structure (fromClassInfo==true)
231+
// and additionally from InnerClasses attribute (fromClassInfo==false)
232+
// The enum constants and record components should only be initialized once
233+
// to avoid losing the constants.
234+
if (fromClassInfo) {
235+
if ((accessFlags & Opcodes.ACC_ENUM) != 0) {
236+
this.enumConstants = new ArrayList<>();
237+
}
238+
if ((accessFlags & Opcodes.ACC_RECORD) != 0) {
239+
this.recordComponents = new ArrayList<>();
240+
}
235241
}
236242
}
237243

0 commit comments

Comments
 (0)