Skip to content

Commit d5d423c

Browse files
committed
Fixed #1599: Added protection against infinite recursion in PhpElementsUtil.getImplementedMethods
1 parent 00cf140 commit d5d423c

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main/java/fr/adrienbrault/idea/symfony2plugin/util/PhpElementsUtil.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -575,15 +575,17 @@ static private PsiElement getArrayKeyValueInsideSignaturePsi(Project project, St
575575
}
576576

577577
public static Method[] getImplementedMethods(@NotNull Method method) {
578-
ArrayList<Method> items = getImplementedMethods(method.getContainingClass(), method, new ArrayList<>());
578+
ArrayList<Method> items = getImplementedMethods(method.getContainingClass(), method, new ArrayList<>(), new HashSet<>());
579579
return items.toArray(new Method[items.size()]);
580580
}
581581

582-
private static ArrayList<Method> getImplementedMethods(@Nullable PhpClass phpClass, @NotNull Method method, ArrayList<Method> implementedMethods) {
583-
if (phpClass == null) {
582+
private static ArrayList<Method> getImplementedMethods(@Nullable PhpClass phpClass, @NotNull Method method, ArrayList<Method> implementedMethods, Set<PhpClass> visitedClasses) {
583+
if (phpClass == null || visitedClasses.contains(phpClass)) {
584584
return implementedMethods;
585585
}
586586

587+
visitedClasses.add(phpClass);
588+
587589
Method[] methods = phpClass.getOwnMethods();
588590
for (Method ownMethod : methods) {
589591
if (PhpLangUtil.equalsMethodNames(ownMethod.getName(), method.getName())) {
@@ -592,10 +594,10 @@ private static ArrayList<Method> getImplementedMethods(@Nullable PhpClass phpCla
592594
}
593595

594596
for(PhpClass interfaceClass: phpClass.getImplementedInterfaces()) {
595-
getImplementedMethods(interfaceClass, method, implementedMethods);
597+
getImplementedMethods(interfaceClass, method, implementedMethods, visitedClasses);
596598
}
597599

598-
getImplementedMethods(phpClass.getSuperClass(), method, implementedMethods);
600+
getImplementedMethods(phpClass.getSuperClass(), method, implementedMethods, visitedClasses);
599601

600602
return implementedMethods;
601603
}

0 commit comments

Comments
 (0)