RFR: 8274779: HttpURLConnection: HttpClient and HttpsClient incorrectly check request method when set to POST [v4]

Daniel Fuchs dfuchs at openjdk.java.net
Tue Oct 19 17:22:53 UTC 2021


On Tue, 19 Oct 2021 13:48:24 GMT, Evan Whelan <ewhelan at openjdk.org> wrote:

>> Hi,
>> 
>> Please review my fix for JDK-8274779 which changes how HttpClient and HttpsClient  checks for equality when comparing request methods. 
>> 
>> When `HttpURLConnection.setRequestMethod` is passed `new String("POST")` rather than the "POST" String literal, the old behaviour resulted in broken HttpClients being reused from the `KeepAliveCache`. 
>> 
>> This is because a call to `HttpClient.available()` was never reachable due to identity equality being used instead of logical equality.
>> 
>> The test case uses an injected KeepAliveCache, to which we put a HttpClient that is unavailable. By comparing the initial HttpClient's `connectTimeout` value to the "cached" client's connectTimeout (1234 vs 4321 respectively) we can assert that these values should never be equal as a new HttpClient should be created in cases where we can no longer use the cached one.
>> 
>> All CI testing is green for this fix.
>> 
>> Kind regards,
>> Evan
>
> Evan Whelan has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Added setInCache to HttpClientAccess to replace reflection

test/jdk/sun/net/www/http/RequestMethodCheck/RequestMethodEquality.java line 30:

> 28:  * @bug 8274779
> 29:  * @library /test/lib
> 30:  * @modules java.base/sun.net.www.http:+open

I think that now you can probably remove `:+open` - since you're no longer using reflection.

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

PR: https://git.openjdk.java.net/jdk/pull/5964


More information about the net-dev mailing list