Skip to content

Commit af41378

Browse files
maksim-grebeniuk-sonarsourcesonartech
authored andcommitted
SONARPY-2756 Make ClassSymbol thread safe (#212)
GitOrigin-RevId: 980450c804dbff3a4a87b90ba392b260ebf1e52d
1 parent 2ccfdf9 commit af41378

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

python-frontend/src/main/java/org/sonar/python/semantic/ClassSymbolImpl.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@
5050

5151
public class ClassSymbolImpl extends SymbolImpl implements ClassSymbol {
5252

53-
private final List<Symbol> superClasses = new ArrayList<>();
54-
private List<String> superClassesFqns = new ArrayList<>();
53+
private final List<Symbol> superClasses = Collections.synchronizedList(new ArrayList<>());
54+
private List<String> superClassesFqns = Collections.synchronizedList(new ArrayList<>());
5555
private List<String> inlinedSuperClassFqn = new ArrayList<>();
56-
private Set<Symbol> allSuperClasses = null;
57-
private Set<Symbol> allSuperClassesIncludingAmbiguousSymbols = null;
56+
private volatile Set<Symbol> allSuperClasses = null;
57+
private volatile Set<Symbol> allSuperClassesIncludingAmbiguousSymbols = null;
5858
private boolean hasSuperClassWithoutSymbol = false;
5959
private final Set<Symbol> members = new HashSet<>();
6060
private Map<String, Symbol> membersByName = null;
@@ -205,9 +205,9 @@ public boolean shouldSearchHierarchyInTypeshed() {
205205
}
206206

207207
@Override
208-
public List<Symbol> superClasses() {
208+
public synchronized List<Symbol> superClasses() {
209209
// In case of symbols coming from TypeShed protobuf, we resolve superclasses lazily
210-
if (!hasAlreadyReadSuperClasses && superClasses.isEmpty() && !superClassesFqns.isEmpty()) {
210+
if (shouldSearchHierarchyInTypeshed()) {
211211
superClassesFqns.stream().map(SymbolUtils::typeshedSymbolWithFQN).forEach(this::addSuperClass);
212212
}
213213
hasAlreadyReadSuperClasses = true;
@@ -362,7 +362,7 @@ public String metaclassFQN() {
362362
return metaclassFQN;
363363
}
364364

365-
private Set<Symbol> allSuperClasses(boolean includeAmbiguousSymbols) {
365+
private synchronized Set<Symbol> allSuperClasses(boolean includeAmbiguousSymbols) {
366366
if (!includeAmbiguousSymbols) {
367367
if (allSuperClasses == null) {
368368
allSuperClasses = new LinkedHashSet<>();

0 commit comments

Comments
 (0)