Skip to content

[pull] master from jhy:master#223

Merged
pull[bot] merged 1 commit intodudw:masterfrom
jhy:master
Apr 5, 2026
Merged

[pull] master from jhy:master#223
pull[bot] merged 1 commit intodudw:masterfrom
jhy:master

Conversation

@pull
Copy link
Copy Markdown

@pull pull bot commented Apr 5, 2026

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.4)

Can you help keep this open source service alive? 💖 Please sponsor : )

@pull pull bot added the ⤵️ pull label Apr 5, 2026
@pull pull bot merged commit 823709f into dudw:master Apr 5, 2026
11 checks passed

@Test
public void bufferedParseWorksWhenCharsetDetectionFullyReadsResponse() throws IOException {
Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
Response.bufferUp
should be avoided because it has been deprecated.

Copilot Autofix

AI 7 days ago

In general, to fix a deprecated method invocation, you replace it with the recommended, non-deprecated alternative while preserving the observable behavior of the code. For jsoup Connection.Response, bufferUp() was used to fully read and buffer the response body so that multiple parses or charset detection logic would work consistently. Modern jsoup exposes higher-level parsing APIs (e.g., parse(), streamParser().complete()) that implicitly handle buffering without requiring an explicit bufferUp() call.

For this specific test in src/test/java/org/jsoup/integration/ConnectTest.java, the only direct usage of the deprecated API in the shown snippet is in bufferedParseWorksWhenCharsetDetectionFullyReadsResponse, at line 427:

Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();

Elsewhere in the same file, the test bufferedStreamParserWorksWhenCharsetDetectionFullyReadsResponse already uses res.streamParser().complete() to force a streaming parse and validate charset behavior without calling bufferUp(). We can mirror that pattern here: keep res as the result of execute() only (dropping .bufferUp()), and then parse via res.streamParser().complete() to force a full read and DOM creation. The assertions can remain exactly the same, because the Document produced by the streaming parser is equivalent for this test case. No new imports are needed; StreamParser is already imported.

Concretely:

  • In bufferedParseWorksWhenCharsetDetectionFullyReadsResponse, change the creation of res to drop .bufferUp().
  • Change Document doc = res.parse(); to Document doc = res.streamParser().complete();.
  • Leave all other lines in the file as-is.

This removes the deprecated bufferUp() call while maintaining the intended behavior of validating charset detection and base URL handling.

Suggested changeset 1
src/test/java/org/jsoup/integration/ConnectTest.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/test/java/org/jsoup/integration/ConnectTest.java b/src/test/java/org/jsoup/integration/ConnectTest.java
--- a/src/test/java/org/jsoup/integration/ConnectTest.java
+++ b/src/test/java/org/jsoup/integration/ConnectTest.java
@@ -424,9 +424,9 @@
 
     @Test
     public void bufferedParseWorksWhenCharsetDetectionFullyReadsResponse() throws IOException {
-        Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();
+        Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute();
 
-        Document doc = res.parse();
+        Document doc = res.streamParser().complete();
         assertEquals("UTF-8", res.charset());
         assertEquals("http://example.com/foo.jpg", doc.expectFirst("img").absUrl("src"));
     }
EOF
@@ -424,9 +424,9 @@

@Test
public void bufferedParseWorksWhenCharsetDetectionFullyReadsResponse() throws IOException {
Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();
Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute();

Document doc = res.parse();
Document doc = res.streamParser().complete();
assertEquals("UTF-8", res.charset());
assertEquals("http://example.com/foo.jpg", doc.expectFirst("img").absUrl("src"));
}
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
@Test
public void bufferedStreamParserWorksWhenCharsetDetectionFullyReadsResponse() throws IOException {
// https://github.com/jhy/jsoup/issues/2483
Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();

Check notice

Code scanning / CodeQL

Deprecated method or constructor invocation Note test

Invoking
Response.bufferUp
should be avoided because it has been deprecated.

Copilot Autofix

AI 7 days ago

In general, to fix deprecated Response.bufferUp() usage, you should replace it with the non-deprecated way of obtaining a buffered body or a parsed Document. For jsoup, calling Response.parse() already consumes and buffers the body internally, and then Response.parse() can be called multiple times safely without needing bufferUp().

In this specific test bufferedStreamParserWorksWhenCharsetDetectionFullyReadsResponse, the goal is to ensure that charset detection that fully reads the response still allows a streaming parse to complete correctly. The current code:

Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();

Document doc = res.streamParser().complete();

can be rewritten so that the buffering side-effect comes from res.parse(), which is not deprecated, and then the streaming parser is exercised on the same response. This keeps semantics as close as possible to the original intent: the response body is fully read once (via parse()), and then the stream parser is run:

  1. Execute the request to get res.
  2. Call res.parse() to fully read and detect charset (this replaces bufferUp()).
  3. Then call res.streamParser().complete() and perform the same assertions.

No new imports are required; we only change the body of this one test method.

Concretely, in src/test/java/org/jsoup/integration/ConnectTest.java, around line 437, replace the execute().bufferUp() call with execute() followed by a res.parse() call on the next line, leaving the rest of the test unchanged.

Suggested changeset 1
src/test/java/org/jsoup/integration/ConnectTest.java

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/test/java/org/jsoup/integration/ConnectTest.java b/src/test/java/org/jsoup/integration/ConnectTest.java
--- a/src/test/java/org/jsoup/integration/ConnectTest.java
+++ b/src/test/java/org/jsoup/integration/ConnectTest.java
@@ -434,7 +434,9 @@
     @Test
     public void bufferedStreamParserWorksWhenCharsetDetectionFullyReadsResponse() throws IOException {
         // https://github.com/jhy/jsoup/issues/2483
-        Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();
+        Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute();
+        // fully read and detect charset, replacing deprecated bufferUp()
+        res.parse();
 
         Document doc = res.streamParser().complete();
         assertEquals("UTF-8", res.charset());
EOF
@@ -434,7 +434,9 @@
@Test
public void bufferedStreamParserWorksWhenCharsetDetectionFullyReadsResponse() throws IOException {
// https://github.com/jhy/jsoup/issues/2483
Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute().bufferUp();
Connection.Response res = Jsoup.connect(FileServlet.urlTo("/htmltests/charset-base.html")).execute();
// fully read and detect charset, replacing deprecated bufferUp()
res.parse();

Document doc = res.streamParser().complete();
assertEquals("UTF-8", res.charset());
Copilot is powered by AI and may make mistakes. Always verify output.
Unable to commit as this autofix suggestion is now outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants