Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8297687

new URI(S,S,S,S) throws exception with incorrect index position reported in the error message



    • Bug
    • Resolution: Fixed
    • P4
    • 20
    •, 17.0.5
    • core-libs
    • None
    • b27
    • x86
    • windows_10


      Originally reported: https://github.com/adoptium/adoptium-support/issues/611

      ### Please provide a brief summary of the bug

      We rely on URI class implements reasonably well RFC-2396. Recently faced a confusing case.

      ### Please provide steps to reproduce where possible

      PS C:\app\jdk-17.0.5+8> bin/jshell
      | Welcome to JShell -- Version 17.0.5
      | For an introduction type: /help intro

      jshell> new URI("ftps", "p.e.local|SIT@p.e.local", "/path", null)
      | Exception java.net.URISyntaxException: Illegal character in authority at index 7: ftps://p.e.local|SIT@p.e.local/path
      | at URI$Parser.fail (URI.java:2974)
      | at URI$Parser.parseAuthority (URI.java:3308)
      | at URI$Parser.parseHierarchical (URI.java:3219)
      | at URI$Parser.parse (URI.java:3175)
      | at URI.<init> (URI.java:708)
      | at URI.<init> (URI.java:809)
      | at (#1:1)

      ### Expected Results

      The message should make sense, the index of the invalid character should be relative to the presented URI string.

      jshell> "ftps://p.e.local|SIT@p.e.local/path".indexOf("|")
      $4 ==> 16

      ### Actual Results

      Above index ``7`` in ``ftps://p.e.local|SIT@p.e.local/path`` results in ``p``.

      jshell> "ftps://p.e.local|SIT@p.e.local/path".charAt(7)
      $3 ==> 'p'

      ### What Java Version are you using?

      openjdk version "17.0.5"

      ### What is your operating system and platform?

      Win 10 on AMD x64

      ### How did you install Java?

      _No response_

      ### Did it work before?

      _No response_

      ### Did you test with other Java versions?


      ### Relevant log output

      _No response_

      ### Extra info

      I'm sure about the incorrect index because ``p`` is a valid char.

      Indeed this evident smell raises subsequent questions.

      For ``|``, it comes from observations that it is the pipe disrupting the URI.

      I'm not sure if ``|`` should or should not be rejected, spec-wise:

      java.net.URI JavaDoc is silent on ``|``, the other category there matches non-US-ASCII chars, but ``|`` is US-ASCII char.

      RFC https://www.ietf.org/rfc/rfc2396.txt mentions ``|`` in the unwise category.


        Issue Links



              dfuchs Daniel Fuchs
              karianna Martijn Verburg
              0 Vote for this issue
              4 Start watching this issue