RFR: 8305763 : Parsing a URI with an underscore goes through a silent exception, negatively impacting performance
Dhamoder Nalla
duke at openjdk.org
Tue Apr 25 17:48:10 UTC 2023
On Wed, 12 Apr 2023 10:31:57 GMT, Daniel Fuchs <dfuchs at openjdk.org> wrote:
>> Issue 8305763 : Using underscores in the name for a URI triggers a silent exception in the java standard library, which consumes 5% of the CPU.
>>
>> Exception:
>> java.net.URISyntaxException: Illegal character in hostname at index N: xyz1_abcd.com
>> at java.base/java.net.URI$Parser.fail(URI.java:2943)
>> at java.base/java.net.URI$Parser.parseHostname(URI.java:3487)
>> at java.base/java.net.URI$Parser.parseServer(URI.java:3329)
>>
>> This exception is silent and does not produce any messages, except for ODP profiler, there is no other evidence that it’s happening (the stack trace above was printed after changes to Java library). The reason for this is because of how the URI creation is implemented in the java.net.URI class. There are two paths for creating a valid URI, and one of them goes through an exception.
>>
>> We can see that if parseServer fails, there is still a way the authority gets assigned and we don’t throw an exception from the method. This means, not being able to parse the server is ok and the exception is silenced. In our case, the server parsing fails because we find an illegal character, as only alphanumeric and dash characters are allowed.
>
> From a quick look at the proposed change, I got the feeling that this change might not be appropriate: I suspect it will let `host` be assigned to the reg_name.
> We want to preserve the long standing behavior that:
>
> jshell> new URI("http://foo_bar:8080/").getHost()
> $1 ==> null
>
> Is this still the case after your proposed changes?
Thanks for reviewing @dfuch,
With this change, the below operation returns hostname "foo_bar"
jshell> new URI("http://foo_bar:8080/").getHost()
I will work on addressing this to keep the old behavior unchanged.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/13430#issuecomment-1522177585
More information about the net-dev
mailing list