RFR: 8377675: java.net.http tests should not depend on ../../../com/sun/net/httpserver test classes [v3]

Daniel Jeliński djelinski at openjdk.org
Fri Feb 13 12:30:51 UTC 2026


On Fri, 13 Feb 2026 12:27:45 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:

>> Some HttpClient tests - like `test/jdk/java/net/httpclient/SmokeTest.java`, depend on non-library test classes that were developed for testing the HttpServer, such as `../../../com/sun/net/httpserver/FileServerHandler.java` which requires compiling using `@compile`.
>> 
>> Instead of depending on HttpServer test classes, these tests should use functionalities from the common servers provided by the `HttpServerAdapters`, offered by the `test/jdk/java/net/httpclient/lib` library. An adapted version of the `../../../com/sun/net/httpserver/FileServerHandler.java` could be provided by the `HttpServerAdapters` helper.
>> 
>> There are also 5 implementations of stand-alone echo handlers in the httpclient test base. This change remove 4 of them, keep only the implementation in `HttpServerAdapters`, and updates all tests that were relying on the removed implementations to use that provided by `HttpServerAdapters`.
>> 
>> This is a test-only change.
>
> Daniel Fuchs has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - Update test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java
>    
>    Co-authored-by: Daniel Jelinski <djelinski1 at gmail.com>
>  - Update test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java
>    
>    Co-authored-by: Daniel Jelinski <djelinski1 at gmail.com>

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 256:

> 254:         /**
> 255:          * This constant can be passed to {@link #sendResponseHeaders(int, long)}
> 256:          * to indicates an empty response.

Suggestion:

         * to indicate an empty response.

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 261:

> 259:         /**
> 260:          * This constant can be passed to {@link #sendResponseHeaders(int, long)}
> 261:          * to indicates that the response will be chunked.

Suggestion:

         * to indicate that the response will be chunked.

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 281:

> 279:          * This method always return {@link #RSPBODY_CHUNKED}
> 280:          */
> 281:         public static long chunkedRsp(long bytes) {

This method has limited utility; chunked response is usually used when the content length is not known. Inline?

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 907:

> 905:                 long responseLength = useXFixed()
> 906:                         ? t.responseLength(bytes.length)
> 907:                         : HttpTestExchange.fixedRsp(bytes.length);

was it supposed to use a chunked response when useXFixed is false?

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 997:

> 995: 
> 996:             int x = 0;
> 997:             while (is.read () != -1) x++;

Suggestion:

            while (is.read() != -1) x++;

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 999:

> 997:             while (is.read () != -1) x++;
> 998:             is.close();
> 999:             File f = new File (docroot, path);

Suggestion:

            File f = new File(docroot, path);

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 1001:

> 999:             File f = new File (docroot, path);
> 1000:             if (!f.exists()) {
> 1001:                 notfound (t, path);

Suggestion:

                notfound(t, path);

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 1007:

> 1005:             String method = t.getRequestMethod();
> 1006:             if (method.equals("HEAD")) {
> 1007:                 rspHeaders.addHeader("Content-Length", Long.toString (f.length()));

Suggestion:

                rspHeaders.addHeader("Content-Length", Long.toString(f.length()));

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 1030:

> 1028:                 String[] list = f.list();
> 1029:                 try (final OutputStream os = t.getResponseBody();
> 1030:                      final PrintStream p = new PrintStream (os)) {

Suggestion:

                     final PrintStream p = new PrintStream(os)) {

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 1047:

> 1045:                     byte[] buf = new byte [16 * 1024];
> 1046:                     int len;
> 1047:                     while ((len=fis.read (buf)) != -1) {

Suggestion:

                    while ((len=fis.read(buf)) != -1) {

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 1048:

> 1046:                     int len;
> 1047:                     while ((len=fis.read (buf)) != -1) {
> 1048:                         os.write (buf, 0, len);

Suggestion:

                        os.write(buf, 0, len);

test/jdk/java/net/httpclient/lib/jdk/httpclient/test/lib/common/HttpServerAdapters.java line 1078:

> 1076:             String s = "<h2>File not found</h2>";
> 1077:             s = s + p + "<p>";
> 1078:             os.write (s.getBytes());

Suggestion:

            os.write(s.getBytes());

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803265706
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803266495
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803537302
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803920737
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803923762
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803926551
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803927082
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803928373
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803930218
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803931421
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803932269
PR Review Comment: https://git.openjdk.org/jdk/pull/29702#discussion_r2803933539


More information about the net-dev mailing list