java.net.http.HttpClient: invalid exception when bad status line is returned

Daniel Fuchs daniel.fuchs at oracle.com
Wed Jan 23 12:32:01 UTC 2019


Hi Dmitry,

Thanks for reporting this.

Right - the IllegalArgumentException is a bit strange there,
and an IOException (or subclass of it) wrapping the 
NumberFormatException would be more appropriate.

If you have OpenJDK author status and a JBS account then you
could log a bug at https://bugs.openjdk.java.net/
otherwise then https://bugs.java.com/bugdatabase/
would be the place.

best regards,

-- daniel

On 23/01/2019 12:16, Dmitry Sivachenko wrote:
> Hello,
> 
> is this ML the correct place to report problems with HttpClient?
> 
> If not, can you please point me to the right place?
> 
> Thanks.
> 
> 
>> On 18 Jan 2019, at 23:57, Dmitry Sivachenko <trtrmitya at gmail.com> wrote:
>>
>> Hello,
>>
>> I am tasting java.net.http.HttpClient with
>>
>> openjdk version "11.0.1" 2018-10-16
>> OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.1+13)
>> OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.1+13, mixed mode)
>>
>> on Mac OS X 10.14.2.
>>
>> Consider the case when server responds with bad (invalid format) status line: "HTTP/1.1 FOO"
>>
>> The following IllegalArgumentException is thrown:
>>
>> Exception in thread "main" java.lang.IllegalArgumentException: For input string: "FOO"
>> 	at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:551)
>> 	at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:119)
>> 	at ru.mitya.test.App.main(App.java:14)
>> Caused by: java.lang.NumberFormatException: For input string: "FOO"
>> 	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
>> 	at java.base/java.lang.Integer.parseInt(Integer.java:652)
>> 	at java.base/java.lang.Integer.parseInt(Integer.java:770)
>> 	at java.net.http/jdk.internal.net.http.Http1HeaderParser.readStatusLineFeed(Http1HeaderParser.java:197)
>> 	at java.net.http/jdk.internal.net.http.Http1HeaderParser.parse(Http1HeaderParser.java:124)
>> 	at java.net.http/jdk.internal.net.http.Http1Response$HeadersReader.handle(Http1Response.java:672)
>> 	at java.net.http/jdk.internal.net.http.Http1Response$HeadersReader.handle(Http1Response.java:603)
>> 	at java.net.http/jdk.internal.net.http.Http1Response$Receiver.accept(Http1Response.java:594)
>> 	at java.net.http/jdk.internal.net.http.Http1Response$HeadersReader.tryAsyncReceive(Http1Response.java:650)
>> 	at java.net.http/jdk.internal.net.http.Http1AsyncReceiver.flush(Http1AsyncReceiver.java:228)
>> 	at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175)
>> 	at java.net.http/jdk.internal.net.http.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147)
>> 	at java.net.http/jdk.internal.net.http.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
>> 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
>> 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
>> 	at java.base/java.lang.Thread.run(Thread.java:834)
>>
>>
>> instead of the expected ProtocolException:
>>
>> Exception in thread "main" java.io.IOException: Invalid status line: "HTTP/1.1 FOO"
>> 	at java.net.http/jdk.internal.net.http.HttpClientImpl.send(HttpClientImpl.java:565)
>> 	at java.net.http/jdk.internal.net.http.HttpClientFacade.send(HttpClientFacade.java:119)
>> 	at ru.mitya.test.App.main(App.java:14)
>> Caused by: java.net.ProtocolException: Invalid status line: "HTTP/1.1 FOO"
>> <...>
>>
>> The suggested fix would be to catch IllegalArgumentException thrown by Integer.parseInt() in readStatusLineFeed() and throw
>> ProtocolException instead of it.
>>
>> What do you think?
>>
>> Thanks.
> 



More information about the net-dev mailing list