Skip to content

Commit c0bd22c

Browse files
cyrille-leclercv1v
andauthored
Prevent StackOverflowError in FlowNode#getParents()
Co-authored-by: Victor Martinez <[email protected]>
1 parent a842ed5 commit c0bd22c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main/java/io/jenkins/plugins/opentelemetry/job/OtelTraceService.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
import javax.annotation.Nonnull;
3232
import javax.annotation.concurrent.Immutable;
3333
import javax.inject.Inject;
34-
import java.util.*;
34+
import java.util.ArrayList;
35+
import java.util.Collection;
36+
import java.util.Collections;
37+
import java.util.List;
38+
import java.util.Objects;
3539
import java.util.concurrent.ConcurrentHashMap;
3640
import java.util.concurrent.ConcurrentMap;
3741
import java.util.logging.Level;
@@ -147,7 +151,13 @@ public void buildListOfAncestors(@Nonnull FlowNode flowNode, @Nonnull List<FlowN
147151
flowNode = startNode;
148152
}
149153
for (FlowNode parentNode : flowNode.getParents()) {
150-
buildListOfAncestors(parentNode, parents);
154+
if (flowNode.equals(parentNode)) {
155+
LOGGER.log(Level.INFO, "buildListOfAncestors(" + flowNode + "): skip parentFlowNode as it is the current node"); // TODO change message to Level.FINE once the cause is understood
156+
} else if (parents.contains(parentNode)) {
157+
LOGGER.log(Level.INFO, "buildListOfAncestors(" + flowNode + "): skip already added " + parentNode); // TODO can we remove this check once the cause is understood?
158+
} else {
159+
buildListOfAncestors(parentNode, parents);
160+
}
151161
}
152162
}
153163

0 commit comments

Comments
 (0)