Code review comment: We don't need to define this list here since it has 2 usages, and they are in 2 different execution paths.

Code before review:
private List<String> getPossibleTypes(TypeSymbol typeSymbol, CodeActionContext context) {
typeSymbol = getRawType(typeSymbol, context);
Set<String> possibleTypes = new HashSet<>();
List<String> finalPossibleTypeSet = new ArrayList<>();
List<TypeSymbol> errorTypes = new ArrayList<>();
if (typeSymbol.typeKind() == TypeDescKind.UNION) {
((UnionTypeSymbol) typeSymbol)
.memberTypeDescriptors()
.stream()
.map(memberTypeSymbol -> getRawType(memberTypeSymbol, context))
.forEach(memberTypeSymbol -> {
if (memberTypeSymbol.typeKind() == TypeDescKind.UNION) {
possibleTypes.addAll(
((UnionTypeSymbol) memberTypeSymbol)
.memberTypeDescriptors()
.stream()
.map(memberTSymbol -> getRawType(memberTSymbol, context))
.map(symbol -> getTypeName(symbol, context))
.collect(Collectors.toList()));
} else {
if (memberTypeSymbol.typeKind() == TypeDescKind.ERROR
|| CommonUtil.getRawType(memberTypeSymbol).typeKind() == TypeDescKind.ERROR) {
errorTypes.add(memberTypeSymbol);
return;
}
possibleTypes.add(getTypeName(memberTypeSymbol, context));
}
});
} else {
String type = getTypeName(typeSymbol, context);
if (!type.equals("any")) {
return Collections.singletonList(type);
}
}
if (!errorTypes.isEmpty()) {
String errorTypeStr = errorTypes.stream()
.map(type -> getTypeName(type, context))
.collect(Collectors.joining("|"));
finalPossibleTypeSet.addAll(possibleTypes.stream()
.filter(type -> !type.equals("any"))
.map(type -> type + "|" + errorTypeStr).collect(Collectors.toSet()));
} else {
finalPossibleTypeSet.addAll(possibleTypes.stream()
.filter(type -> !type.equals("any"))
.collect(Collectors.toSet()));
}
return finalPossibleTypeSet;
}

Line under review: List<String> finalPossibleTypeSet = new ArrayList<>();

Code after addressing the review:
private List<String> getPossibleTypes(TypeSymbol typeSymbol, CodeActionContext context) {
typeSymbol = getRawType(typeSymbol, context);
Set<String> possibleTypes = new HashSet<>();
List<TypeSymbol> errorTypes = new ArrayList<>();
if (typeSymbol.typeKind() == TypeDescKind.UNION) {
((UnionTypeSymbol) typeSymbol)
.memberTypeDescriptors()
.stream()
.map(memberTypeSymbol -> getRawType(memberTypeSymbol, context))
.forEach(memberTypeSymbol -> {
if (memberTypeSymbol.typeKind() == TypeDescKind.UNION) {
possibleTypes.addAll(
((UnionTypeSymbol) memberTypeSymbol)
.memberTypeDescriptors()
.stream()
.map(memberTSymbol -> getRawType(memberTSymbol, context))
.map(symbol -> getTypeName(symbol, context))
.collect(Collectors.toList()));
} else if (memberTypeSymbol.typeKind() == TypeDescKind.ERROR ||
CommonUtil.getRawType(memberTypeSymbol).typeKind() == TypeDescKind.ERROR) {
errorTypes.add(memberTypeSymbol);
} else {
possibleTypes.add(getTypeName(memberTypeSymbol, context));
}
});
} else {
String type = getTypeName(typeSymbol, context);
if (!"any".equals(type)) {
return Collections.singletonList(type);
}
}
if (!errorTypes.isEmpty()) {
String errorTypeStr = errorTypes.stream()
.map(type -> getTypeName(type, context))
.collect(Collectors.joining("|"));
return possibleTypes.stream()
.filter(type -> !"any".equals(type))
.map(type -> type + "|" + errorTypeStr)
.collect(Collectors.toList());
}
return possibleTypes.stream()
.filter(type -> !"any".equals(type))
.collect(Collectors.toList());
}