Skip to content

Commit c161b75

Browse files
SONARPY-1889 Fix non-deterministic stubFilesSymbols API for sonar-security (#1814)
1 parent 6be593a commit c161b75

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

python-frontend/src/main/java/org/sonar/python/semantic/v2/SymbolsModuleTypeProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private Optional<ModuleType> createModuleTypeFromProjectLevelSymbolTable(String
7171
}
7272

7373
private Optional<ModuleType> createModuleTypeFromTypeShed(String moduleName, String moduleFqn, ModuleType parent) {
74-
return Optional.ofNullable(TypeShed.symbolsForModule(moduleFqn))
74+
return Optional.ofNullable(TypeShed.symbolsForModuleWithoutStoreInCache(moduleFqn))
7575
.filter(Predicate.not(Map::isEmpty))
7676
.map(typeShedModuleSymbols -> createModuleFromSymbols(moduleName, parent, typeShedModuleSymbols.values()));
7777
}

python-frontend/src/main/java/org/sonar/python/types/TypeShed.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.util.HashSet;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.Optional;
3132
import java.util.Set;
3233
import java.util.stream.Collectors;
3334
import javax.annotation.CheckForNull;
@@ -132,6 +133,13 @@ public static Map<String, Symbol> symbolsForModule(String moduleName) {
132133
return TypeShed.typeShedSymbols.get(moduleName);
133134
}
134135

136+
public static Map<String, Symbol> symbolsForModuleWithoutStoreInCache(String moduleName) {
137+
return Optional.of(moduleName)
138+
.filter(TypeShed.typeShedSymbols::containsKey)
139+
.map(TypeShed.typeShedSymbols::get)
140+
.orElseGet(() -> searchTypeShedForModule(moduleName));
141+
}
142+
135143
@CheckForNull
136144
public static Symbol symbolWithFQN(String stdLibModuleName, String fullyQualifiedName) {
137145
Map<String, Symbol> symbols = symbolsForModule(stdLibModuleName);

0 commit comments

Comments
 (0)