On Wed, 4 Nov 2020 15:18:01 GMT, Chris Hegarty <[email protected]> wrote:
>> Hi,
>>
>> Could someone please review our code for JDK-8252304: 'Seed an
>> HttpRequest.Builder from an existing HttpRequest'?
>>
>> This RFR proposes a new factory method for creating a new `HttpRequest`
>> builder from an existing `HttpRequest`.
>> This method can be used to build a new request equivalent to the given
>> request, but with different attributes. For instance, it will allow the user
>> to take an existing request and add or change a particular header, provide a
>> new `URI`, etc.
>>
>>
>> Kind regards,
>> Patrick & Chris
>
> src/java.net.http/share/classes/java/net/http/HttpRequest.java line 344:
>
>> 342: throw ex;
>> 343: } catch (RuntimeException r) {
>> 344: throw new IllegalArgumentException("Illegal request
>> parameters", r);
>
> I'm a little concerned about this. It seems unnecessary, and adds complexity
> to an otherwise straightforward piece of code. Any accessor of the given
> request that throws should probably just be allowed to flow out. If needed,
> we could even mention that in the specification.
The current code side step the issue of having to explain in the spec that any
kind of `RuntimeException` could be propagated upwards. With this, calling code
can just try catch `IAE`. It's a little more user-friendly.
-------------
PR: https://git.openjdk.java.net/jdk/pull/1059