Replace printStackTrace with proper error handling#2011
Conversation
| result.setFile(TestFileUtils.createTempFile("")); | ||
| } catch (IOException e) { | ||
| e.printStackTrace(); | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()inDefaultArtifactResolverTestwith exceptions that fail the test path on unexpectedIOException. - Remove
printStackTrace()from concurrency tests that already capture errors viaAtomicReference. - Introduce local counters in
DependencyCollectorDelegate.Resultsto avoid relying onCollectResultlist 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.
| try { | ||
| set(key, Boolean.TRUE); | ||
| assertEquals(Boolean.TRUE, get(key)); | ||
| } catch (Throwable t) { | ||
| error.compareAndSet(null, t); | ||
| t.printStackTrace(); | ||
| } |
| try { | ||
| put(key, Boolean.TRUE); | ||
| assertEquals(Boolean.TRUE, get(key)); | ||
| } catch (Throwable t) { | ||
| error.compareAndSet(null, t); | ||
| t.printStackTrace(); | ||
| } |
…concurrency tests
gnodet
left a comment
There was a problem hiding this comment.
Clean PR that correctly replaces silent printStackTrace() calls with proper error propagation. The UncheckedIOException wrapper and AssertionError(Throwable) patterns are idiomatic and ensure test failures are no longer silently swallowed.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of gnodet
Fixes #1999
Changes:
e.printStackTrace()withthrow new RuntimeException(e)so tests properly fail on IO errors instead of silently printingt.printStackTrace()— error already captured in AtomicReference and assertedresult.getExceptions().size()/result.getCycles().size()for thread safety during concurrent collection