Skip to content

Commit 776448d

Browse files
committed
Working on stackoverflow error
1 parent 868dde5 commit 776448d

3 files changed

Lines changed: 17 additions & 7 deletions

File tree

project/Dependencies.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ import sbt._
22

33
object Dependencies {
44

5-
private val circeVersion = "0.14.13"
5+
private val circeVersion = "0.14.14"
66
lazy val circeCore = "io.circe" %% "circe-core" % circeVersion
77
lazy val circeGeneric = "io.circe" %% "circe-generic" % circeVersion
88
lazy val circeParser = "io.circe" %% "circe-parser" % circeVersion
99

1010
lazy val jansi = "org.fusesource.jansi" % "jansi" % "2.4.2"
1111

1212
lazy val logback = "ch.qos.logback" % "logback-classic" % "1.5.18"
13-
lazy val methanol = "com.github.mizosoft.methanol" % "methanol" % "1.8.2"
13+
lazy val methanol = "com.github.mizosoft.methanol" % "methanol" % "1.8.3"
1414
lazy val munit = "org.scalameta" %% "munit" % "1.1.1"
1515
lazy val picocli = "info.picocli" % "picocli" % "4.7.7"
1616

1717
lazy val slf4jJdk = "org.slf4j" % "slf4j-jdk-platform-logging" % "2.0.17"
1818

19-
private val tapirVersion = "1.11.34"
19+
private val tapirVersion = "1.11.35"
2020
lazy val tapirStubServer = "com.softwaremill.sttp.tapir" %% "tapir-sttp-stub-server" % tapirVersion
2121
lazy val tapirSwagger = "com.softwaremill.sttp.tapir" %% "tapir-swagger-ui-bundle" % tapirVersion
2222
lazy val tapirCirce = "com.softwaremill.sttp.tapir" %% "tapir-json-circe" % tapirVersion

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.11.1")
44
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.6.4")
55
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.10.0")
66
addSbtPlugin("org.planet42" % "laika-sbt" % "0.19.5")
7-
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4")
7+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.5")

src/main/scala/org/fathomnet/worms/Data.scala

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import org.fathomnet.worms.io.WormsConcept
2020
*/
2121
final case class Data(rootNode: WormsNode, wormsConcepts: Seq[WormsConcept]):
2222

23+
private val log = System.getLogger(getClass.getName)
24+
2325
/**
2426
* Map of [nodeName, Node] for both the name and alternate name of the node.
2527
*/
@@ -42,10 +44,18 @@ final case class Data(rootNode: WormsNode, wormsConcepts: Seq[WormsConcept]):
4244
*/
4345
lazy val parents: SortedMap[String, WormsNode] =
4446
val map = SortedMap.newBuilder[String, WormsNode]
47+
val visited = scala.collection.mutable.Set.empty[String] // avoids cyclic relations in the tree
48+
4549
def add(node: WormsNode): Unit =
46-
node.children.foreach(n => map += n.name -> node)
47-
node.children.foreach(n => n.alternateNames.foreach(n => map += n -> node))
48-
node.children.foreach(add)
50+
if visited.add(node.name) then
51+
node.children.foreach(n => map += n.name -> node)
52+
node.children.foreach(n => n.alternateNames.foreach(n => map += n -> node))
53+
node.children.foreach(add)
54+
else
55+
log.log(
56+
System.Logger.Level.WARNING,
57+
s"Node ${node.name} already visited, skipping to avoid cycles."
58+
)
4959
add(rootNode)
5060
map.result()
5161

0 commit comments

Comments
 (0)