Harmony
  1. Harmony
  2. HARMONY-1126

[classlib][net] unexpected URISyntaxException for URI.parseServerAuthority()

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None
    • Patch Info:
      Patch Available

      Description

      The Harmony method URI.parseServerAuthority() throws URISyntaxException for uri 'file://C:/1.txt' while RI returns correct value.

      ==================== test.java =====================
      import java.net.*;

      public class test {

      public static void main (String[] args) throws Exception

      { System.out.println("res = " + URI.create("file://C:/1.txt").parseServerAuthority()); }


      }
      ================================================

      Output:
      C:\tmp\tmp17>C:\jrockit-jdk1.5.0-windows-ia32\bin\java.exe -cp . -showversion test
      java version "1.5.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
      BEA WebLogic JRockit(R) (build dra-38972-20041208-2001-win-ia32, R25.0.0-75, GC: System optimized over throughput (initial strategy singleparpar))

      res = file://C:/1.txt

      C:\tmp\tmp17>C:\harmony\classlib1.5\deploy\jdk\jre\bin\java.exe -cp . -showversion test
      java version 1.5 (subset)

      (c) Copyright 1991, 2006 The Apache Software Foundation or its licensors, as applicable.
      Exception in thread "main" java.net.URISyntaxException: Invalid port number at index 2: C:
      at java.net.URI$Helper.parseAuthority(URI.java:417)
      at java.net.URI$Helper.access$1500(URI.java:22)
      at java.net.URI.parseServerAuthority(URI.java:1217)
      at test.main(test.java:6)

      1. H-1126.patch
        2 kB
        Mikhail Markov
      2. URITest.patch
        0.8 kB
        Vladimir Ivanov

        Activity

        Vladimir Ivanov created issue -
        Hide
        Vladimir Ivanov added a comment -

        unit test.
        Seems, that patch will be system dependent (special handling for Win should be added)

        Show
        Vladimir Ivanov added a comment - unit test. Seems, that patch will be system dependent (special handling for Win should be added)
        Vladimir Ivanov made changes -
        Field Original Value New Value
        Attachment URITest.patch [ 12338552 ]
        Hide
        spark shen added a comment -

        I think RI is more reasonable, since according to RFC-2396 (3.2.2. Server-based Naming Authority)

        hostport = host [ ":" port ]
        host = hostname | IPv4address
        hostname = *( domainlabel "." ) toplabel [ "." ]
        domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
        toplabel = alpha | alpha *( alphanum | "-" ) alphanum

        IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
        port = *digit

        ':' only appears in [":"port] part, and never appears in host part.
        Correct me if I am wrong.

        Best regards

        Show
        spark shen added a comment - I think RI is more reasonable, since according to RFC-2396 (3.2.2. Server-based Naming Authority) hostport = host [ ":" port ] host = hostname | IPv4address hostname = *( domainlabel "." ) toplabel [ "." ] domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum toplabel = alpha | alpha *( alphanum | "-" ) alphanum IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit port = *digit ':' only appears in [":"port] part, and never appears in host part. Correct me if I am wrong. Best regards
        Hide
        Mikhail Markov added a comment -

        RI API documentation for constructor of URI class clearly says that:
        This constructor parses the given string exactly as specified by the grammar in RFC 2396, Appendix A, except for the following deviations:
        ...
        Hostnames in host components that comprise only a single domain label are permitted to start with an alphanum character. This seems to be the intent of RFC 2396 section 3.2.2 although the grammar does not permit it. The consequence of this deviation is that the authority component of a hierarchical URI such as s://123, will parse as a server-based authority.

        Show
        Mikhail Markov added a comment - RI API documentation for constructor of URI class clearly says that: This constructor parses the given string exactly as specified by the grammar in RFC 2396, Appendix A, except for the following deviations: ... Hostnames in host components that comprise only a single domain label are permitted to start with an alphanum character. This seems to be the intent of RFC 2396 section 3.2.2 although the grammar does not permit it. The consequence of this deviation is that the authority component of a hierarchical URI such as s://123, will parse as a server-based authority.
        Hide
        Mikhail Markov added a comment -

        Here is the patch for the code + unit test.
        It's not platform-specific as there was just a error in URI's port parsing if it's empty.

        Show
        Mikhail Markov added a comment - Here is the patch for the code + unit test. It's not platform-specific as there was just a error in URI's port parsing if it's empty.
        Mikhail Markov made changes -
        Attachment H-1126.patch [ 12347892 ]
        Alexei Zakharov made changes -
        Patch Info [Patch Available]
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Hide
        Tim Ellison added a comment -

        Thanks Vladimir/Mikhail,

        Patch applied to LUNI module at repo revision r491780.

        Please check that the patch was applied as you expected.

        Show
        Tim Ellison added a comment - Thanks Vladimir/Mikhail, Patch applied to LUNI module at repo revision r491780. Please check that the patch was applied as you expected.
        Tim Ellison made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Vladimir Ivanov added a comment -

        verified, thanks!

        Show
        Vladimir Ivanov added a comment - verified, thanks!
        Hide
        Tim Ellison added a comment -

        Verified by Vladimir.

        Show
        Tim Ellison added a comment - Verified by Vladimir.
        Tim Ellison made changes -
        Status Resolved [ 5 ] Closed [ 6 ]

          People

          • Assignee:
            Tim Ellison
            Reporter:
            Vladimir Ivanov
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development