Skip to content

Fix [MDEP-931] Replace PrintWriter with Writer in AbstractSerializing Visitor and subclasses #530

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Ndacyayisenga-droid
Copy link
Contributor

@Ndacyayisenga-droid Ndacyayisenga-droid commented May 20, 2025

Following this checklist to help us incorporate your
contribution quickly and easily:

Fixes https://issues.apache.org/jira/browse/MDEP-931

cc @elharo

  • Your pull request should address just one issue, without pulling in other changes.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Each commit in the pull request should have a meaningful subject line and body.
    Note that commits might be squashed by a maintainer on merge.
  • Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied.
    This may not always be possible but is a best-practice.
  • Run mvn verify to make sure basic checks pass.
    A more thorough check will be performed on your pull request automatically.
  • You have run the integration tests successfully (mvn -Prun-its verify).

If your pull request is about ~20 lines of code you don't need to sign an
Individual Contributor License Agreement if you are unsure
please ask on the developers list.

To make clear that you license your contribution under
the Apache License Version 2.0, January 2004
you have to acknowledge this by using the following check-box.

writer.flush();
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write to DOT output", e);
Copy link
Contributor

@elharo elharo May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

for (DependencyNode child : children) {
writer.println("\t\"" + node.toNodeString() + "\" -> \"" + child.toNodeString() + "\" ; ");
// Write the accumulated output to the provided writer
writer.write(stringWriter.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be happening in the visit method. The visitor should be building the report in memory that is only later written to a stream. Alternately the API should change so that visit can throw an IOException.

if (node.getParent() == null || node.getParent() == node) {
writer.write(" } ");
try {
StringWriter stringWriter = new StringWriter();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need the stringwriter here. Just use the writer directly

writer.flush();
return true;
} catch (IOException e) {
throw new UncheckedIOException("Failed to write GraphML node", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm starting to see how this should work. Either drop all the stringwiters and write straight onto the writer, or use stringwriters to build up a report that is written after the visitor is finished.

writer.write(sb.toString());
writer.flush();
} catch (IOException e) {
throw new UncheckedIOException("Failed to write JSON output", e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed; this method can and should throw the IOException directly since it's private

return true;
try {
if (node.getParent() == null || node.getParent() == node) {
writer.flush();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly here and only here content should be written to the stream; I'm not sure

@elharo
Copy link
Contributor

elharo commented May 30, 2025

CI failing on a known flaky test:

Error:  Failures: 
Error:    TestUnpackMojo.testUnpackOverWriteIfNewer:513 unpackedFile '/var/folders/tp/bfmjfn9s0hd59bm9z80j3mgm0000gn/T/unpack2709761897097392486/outputDirectory/testGroupId-snapshot-2.0-SNAPSHOT-null-jar.txt' lastModified() == 1748599196000: should be different. Actual: 1748599196000
[INFO] 

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

Successfully merging this pull request may close these issues.

2 participants