Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DotExporter exports outdated version of the graph #1130

Open
stheid opened this issue Sep 19, 2022 · 0 comments
Open

DotExporter exports outdated version of the graph #1130

stheid opened this issue Sep 19, 2022 · 0 comments

Comments

@stheid
Copy link

stheid commented Sep 19, 2022

 * JGraphT version:                                'org.jgrapht:jgrapht-io:1.5.1'
 * Java version (java -version)/platform:  java-11-openjdk (linux)

Issue
When using Nodes that contain classes, the dotexporter seems to export a cached version of the graph instead of properly evaluating all classes toString. This causes wrong outputs.

Steps to reproduce (small coding example)

import org.jgrapht.graph.DefaultDirectedGraph
import org.jgrapht.graph.DefaultEdge
import org.jgrapht.nio.dot.DOTExporter
import java.io.File


class Node(val wrapper: StringWrap)
class StringWrap(var value: String)

fun main() {
    val graph = DefaultDirectedGraph<Node, DefaultEdge>(DefaultEdge::class.java)
    val node1 = Node(StringWrap("old"))
    graph.addVertex(node1)

    val exporter = DOTExporter<Node, DefaultEdge> { """"${it.wrapper.value}"""" }
    exporter.exportGraph(graph, File("old.dot").bufferedWriter()) // <- commenting out this line will eliviate the bug
    node1.wrapper.value = "new"
    exporter.exportGraph(graph, File("new.dot").bufferedWriter())
}

Than new.dot contains the old data

strict digraph G {
  "old";
}

Expected behaviour

new.dot containing the updated data

strict digraph G {
  "new";
}

Other information
The problem is actually caused by the first export call. This somehow caches information inside the exporter. When commenting out the first export call the result is correct.

Also it is importaint that the data is contained inside a class. It seems that it checks if the class reference has changed. changing the updating code to node1.wrapper = new StringWrap("new") will work!.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant