Fixed PIEAE caused by PyBuiltinCache.getStdlibType() (EA-37595)

This commit is contained in:
Andrey Vlasovskikh
2012-08-20 21:54:39 +04:00
parent 604fecf05a
commit 60b18d7fc6
@@ -318,8 +318,7 @@ public class PyBuiltinCache {
synchronized (myStdlibTypeCache) {
final Ref<PyType> ref = myStdlibTypeCache.get(key);
if (ref != null) {
final PyType pyType = ref.get();
if (pyType instanceof PyClassType && !((PyClassType)pyType).isValid()) {
if (!isValid(ref.get())) {
myStdlibTypeCache.clear();
return null;
}
@@ -328,6 +327,31 @@ public class PyBuiltinCache {
}
}
private static boolean isValid(@Nullable PyType type) {
if (type instanceof PyCollectionType) {
final PyType elementType = ((PyCollectionType)type).getElementType(TypeEvalContext.fastStubOnly(null));
if (!isValid(elementType)) {
return false;
}
}
if (type instanceof PyClassType) {
return ((PyClassType)type).isValid();
}
else if (type instanceof PyUnionType) {
for (PyType member : ((PyUnionType)type).getMembers()) {
if (!isValid(member)) {
return false;
}
}
return true;
}
else if (type instanceof PyFunctionType) {
return ((PyFunctionType)type).getFunction().isValid();
}
return true;
}
public void storeStdlibType(@NotNull String key, @Nullable PyType result) {
synchronized (myStdlibTypeCache) {
myStdlibTypeCache.put(key, new Ref<PyType>(result));