fix(xml): close DTD resolver resources - #3334
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughTestNG 7.13.0 updates DTD resolution to bound URL waits, close resources, handle one redirect, and buffer DTD content. Tests cover timeout configuration, resource cleanup, buffered content, and redirect handling. ChangesDTD resolver resource handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant XMLParser
participant TestNGContentHandler
participant DTDServer
XMLParser->>TestNGContentHandler: Resolve external DTD
TestNGContentHandler->>DTDServer: Open connection with timeouts
DTDServer-->>TestNGContentHandler: DTD content or one redirect
TestNGContentHandler-->>XMLParser: Buffered InputSource
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java`:
- Around line 76-80: Update the normal known-DTD path in loadDtdUsingClassLoader
to read the returned classpath stream into a byte array inside
try-with-resources, close it, and construct InputSource from the buffered bytes
rather than passing the stream directly to SAX.
- Around line 92-105: In the URL-reading flow around httpConnection and
getResponseCode(), disable HttpURLConnection’s automatic redirect handling
before reading the response code by configuring the connection instance.
Preserve the existing followRedirect status checks and recursive one-hop
handling, and add coverage proving a two-redirect chain follows only the first
redirect.
In `@testng-core/src/test/java/test/xml/TestNGContentHandlerTest.java`:
- Around line 61-69: Update the test around TestNGContentHandler and the
temporary dtd path so cleanup is unconditional: wrap handler.resolveEntity and
its assertions in a try/finally and call Files.deleteIfExists(dtd) from finally,
removing the current success-path Files.delete(dtd) call.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: bce5ec43-e068-4309-b128-31c20a5e29a1
📒 Files selected for processing (4)
CHANGES.txttestng-core/src/main/java/org/testng/xml/TestNGContentHandler.javatestng-core/src/test/java/org/testng/xml/TestNGContentHandlerTestSupport.javatestng-core/src/test/java/test/xml/TestNGContentHandlerTest.java
|
Thanks — addressed all three findings in
Validation: focused |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@testng-core/src/test/java/test/xml/TestNGContentHandlerTest.java`:
- Around line 63-78: Update resolverBuffersAndClosesExternalDtd to use an
instrumented URLConnection input stream that records closure, and verify the
source stream is closed before resolveEntity returns. Replace the temporary-file
deletion check with an assertion on that closure state, then separately read the
returned byte stream to confirm the buffered content remains available without
relying on the test closing the handler-owned source stream.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4d54f5b8-b0bb-4c43-854c-dd85881d7b1f
📒 Files selected for processing (3)
testng-core/src/main/java/org/testng/xml/TestNGContentHandler.javatestng-core/src/test/java/org/testng/xml/TestNGContentHandlerTestSupport.javatestng-core/src/test/java/test/xml/TestNGContentHandlerTest.java
🚧 Files skipped from review as they are similar to previous changes (2)
- testng-core/src/test/java/org/testng/xml/TestNGContentHandlerTestSupport.java
- testng-core/src/main/java/org/testng/xml/TestNGContentHandler.java
|
Thanks — addressed the follow-up in The focused |
| return readUrlAsInputSource(url); | ||
| } | ||
| try (InputStream input = stream) { | ||
| return new InputSource(new ByteArrayInputStream(input.readAllBytes())); |
There was a problem hiding this comment.
add a comment to explain why bytes are read instead of new InputSource(input)
| } | ||
| } | ||
|
|
||
| static InputSource readUrlAsInputSource(URL url) throws IOException { |
There was a problem hiding this comment.
only used by tests, move it into the test workspace
Fixes #3316.
Summary
Validation
./gradlew :testng-core:test --tests test.xml.TestNGContentHandlerTest --rerun-tasks./gradlew build./gradlew autostyleCheck./gradlew rewriteDryRun -PfailOnRewriteDryRun=truegit diff --checkDid you remember to?
CHANGES.txt./gradlew autostyleApplySummary by CodeRabbit