Skip to content

Replace printStackTrace with proper error handling#2011

Open
elharo wants to merge 2 commits into
masterfrom
fix-printstacktrace-1999
Open

Replace printStackTrace with proper error handling#2011
elharo wants to merge 2 commits into
masterfrom
fix-printstacktrace-1999

Conversation

@elharo

@elharo elharo commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #1999

Changes:

  • DefaultArtifactResolverTest: Replace e.printStackTrace() with throw new RuntimeException(e) so tests properly fail on IO errors instead of silently printing
  • DefaultSessionDataTest: Remove redundant t.printStackTrace() — error already captured in AtomicReference and asserted
  • DefaultRepositoryCacheTest: Same as DefaultSessionDataTest
  • DependencyCollectorDelegate: Use local counter fields instead of result.getExceptions().size() / result.getCycles().size() for thread safety during concurrent collection

result.setFile(TestFileUtils.createTempFile(""));
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no catch is needed here and below. Just let the IOException bubble up and fail the test so you don't have to wrap the exception.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses issue #1999 by eliminating printStackTrace() usage in tests and tightening failure behavior, while also adjusting dependency collection bookkeeping during concurrent graph collection.

Changes:

  • Replace printStackTrace() in DefaultArtifactResolverTest with exceptions that fail the test path on unexpected IOException.
  • Remove printStackTrace() from concurrency tests that already capture errors via AtomicReference.
  • Introduce local counters in DependencyCollectorDelegate.Results to avoid relying on CollectResult list sizes while enforcing max exception/cycle limits.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
maven-resolver-impl/src/test/java/org/eclipse/aether/internal/impl/DefaultArtifactResolverTest.java Converts temp-file IOException handling from printing to throwing so tests fail fast.
maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DependencyCollectorDelegate.java Adds internal counters for exception/cycle limit checks during collection.
maven-resolver-api/src/test/java/org/eclipse/aether/DefaultSessionDataTest.java Removes printStackTrace() from concurrency test worker threads.
maven-resolver-api/src/test/java/org/eclipse/aether/DefaultRepositoryCacheTest.java Removes printStackTrace() from concurrency test worker threads.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 113 to 118
try {
set(key, Boolean.TRUE);
assertEquals(Boolean.TRUE, get(key));
} catch (Throwable t) {
error.compareAndSet(null, t);
t.printStackTrace();
}
Comment on lines 77 to 82
try {
put(key, Boolean.TRUE);
assertEquals(Boolean.TRUE, get(key));
} catch (Throwable t) {
error.compareAndSet(null, t);
t.printStackTrace();
}
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.

printStackTrace() used instead of logging in tests

2 participants