[ https://issues.apache.org/jira/browse/MDEP-931?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17955275#comment-17955275 ]
ASF GitHub Bot commented on MDEP-931: ------------------------------------- elharo commented on code in PR #530: URL: https://github.com/apache/maven-dependency-plugin/pull/530#discussion_r2115558075 ########## src/main/java/org/apache/maven/plugins/dependency/tree/DOTDependencyNodeVisitor.java: ########## @@ -47,29 +50,45 @@ public DOTDependencyNodeVisitor(Writer writer) { */ @Override public boolean visit(DependencyNode node) { - if (node.getParent() == null || node.getParent() == node) { - writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator()); - } + try { + StringWriter stringWriter = new StringWriter(); + if (node.getParent() == null || node.getParent() == node) { + writer.write("digraph \"" + node.toNodeString() + "\" { " + System.lineSeparator()); + } - // Generate "currentNode -> Child" lines + // Generate "currentNode -> Child" lines - List<DependencyNode> children = node.getChildren(); + List<DependencyNode> children = node.getChildren(); + for (DependencyNode child : children) { + stringWriter.write("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ;\n"); + } - for (DependencyNode child : children) { - writer.println("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; "); + // Write the accumulated output to the provided writer + writer.write(stringWriter.toString()); + writer.flush(); + return true; + } catch (IOException e) { + throw new UncheckedIOException("Failed to write to DOT output", e); Review Comment: probably better than what we had before, but really we need a complete rethink of this API that separates I/O from string buliding and lets it throw exceptions > AbstractSerializingVisitor should not use PrintWriter > ----------------------------------------------------- > > Key: MDEP-931 > URL: https://issues.apache.org/jira/browse/MDEP-931 > Project: Maven Dependency Plugin (Moved to GitHub Issues) > Issue Type: Improvement > Reporter: Elliotte Rusty Harold > Priority: Minor > > See https://github.com/apache/maven-dependency-plugin/pull/391/files > AbstractSerializingVisitor uses a PrintWriter which swallows exceptions. It > should use a regular Writer instead. > This is exposed in the protected API so fixing this is ugly. -- This message was sent by Atlassian Jira (v8.20.10#820010)