Harmony
  1. Harmony
  2. HARMONY-1158

[classlib][luni]Compatibility: java.net.URL new URL("ss", null, -3, null) throws MalformedURLException while RI throws NPE

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      Compatibility. Different order of exceptions.

      RI throws unspecified NPE in java.net.URL("ss", null, -3, null) constructor if host ==null while Harmony at first checks port and throws MalformedURLException.
      If host != null both RI and Harmony throw MalformedURLException.
      =============test.java=============
      import java.net.*;

      public class test {
      public static void main (String[] args) {
      try

      { new URL("ss", "0", -3, null); }

      catch (Exception e)

      { e.printStackTrace(); }
      try { new URL("ss", null, -3, null); } catch (Exception e) { e.printStackTrace(); }

      }
      }

      =======================================

      Output on RI:
      java.net.MalformedURLException: Invalid port number :-3
      at java.net.URL.<init>(URL.java:373)
      at java.net.URL.<init>(URL.java:283)
      at test.main(test.java:7)
      java.lang.NullPointerException
      at java.net.Parts.<init>(URL.java:1259)
      at java.net.URL.<init>(URL.java:380)
      at java.net.URL.<init>(URL.java:283)
      at test.main(test.java:13)

      Output on Harmony:
      java.net.MalformedURLException: Port out of range: -3
      at java.net.URL.<init>(URL.java:393)
      at java.net.URL.<init>(URL.java:367)
      at test.main(test.java:7)
      java.net.MalformedURLException: Port out of range: -3
      at java.net.URL.<init>(URL.java:393)
      at java.net.URL.<init>(URL.java:367)

        Activity

        Hide
        Alexei Zakharov added a comment -

        Closed as WON'T FIX.

        Show
        Alexei Zakharov added a comment - Closed as WON'T FIX.
        Hide
        Mikhail Markov added a comment -

        I've also investigated this issue and agree with Andrew and Ilya - RI's logic seems very weird and it's hard to reproduce it.

        +1 for moving it to Non-bug difference and closing.

        Show
        Mikhail Markov added a comment - I've also investigated this issue and agree with Andrew and Ilya - RI's logic seems very weird and it's hard to reproduce it. +1 for moving it to Non-bug difference and closing.
        Hide
        Andrew Zhang added a comment -

        Ilya, I agree with you. Spec has explicitly pointed out "No validation of the inputs is performed by this constructor."

        The tests show that the exception thrown sequence is uncertain and implemention-dependent.

        If no application and test cases are broken by currenty Harmony code, I suggest not fix the problem.

        Best regards,
        Andrew

        Show
        Andrew Zhang added a comment - Ilya, I agree with you. Spec has explicitly pointed out "No validation of the inputs is performed by this constructor." The tests show that the exception thrown sequence is uncertain and implemention-dependent. If no application and test cases are broken by currenty Harmony code, I suggest not fix the problem. Best regards, Andrew
        Hide
        Ilya Okomin added a comment -

        I believe this case is implementation dependent. If you look in the spec you can find phrase "No validation of the inputs is performed by this constructor." at the end. Thus all thrown exceptions during initialization is based on the inner logics. To be compatible with the RI we have to have the same inner logics that is impossible, because of it is private.
        I was trying to catch this logics based on the constructor playing with arguments combination (correct/incorrect) and found that it is not trivial on RI:
        1. new URL("ss", "0", -3, null);
        java.net.MalformedURLException: Invalid port number :-3

        2. new URL("ss", null, -3, null);
        java.lang.NullPointerException

        3. new URL("ss", "0", -3, "file");
        java.net.MalformedURLException: Invalid port number :-3

        4. new URL("ss", null, -3, "file");
        java.net.MalformedURLException: unknown protocol: ss

        5. new URL("ss", "0", -1, null);
        java.lang.NullPointerException

        As you can see: in 2 and 4 host is null, but we throw different exceptions.
        If we assume that NPE depends on file ?= null (see 2 and 5) than it is false for the 1 case!!

        I would suggest not to make any changes in the URL class constructor if existed implementation of URL class works correct and passes other unit tests.

        Show
        Ilya Okomin added a comment - I believe this case is implementation dependent. If you look in the spec you can find phrase "No validation of the inputs is performed by this constructor." at the end. Thus all thrown exceptions during initialization is based on the inner logics. To be compatible with the RI we have to have the same inner logics that is impossible, because of it is private. I was trying to catch this logics based on the constructor playing with arguments combination (correct/incorrect) and found that it is not trivial on RI: 1. new URL("ss", "0", -3, null); java.net.MalformedURLException: Invalid port number :-3 2. new URL("ss", null, -3, null); java.lang.NullPointerException 3. new URL("ss", "0", -3, "file"); java.net.MalformedURLException: Invalid port number :-3 4. new URL("ss", null, -3, "file"); java.net.MalformedURLException: unknown protocol: ss 5. new URL("ss", "0", -1, null); java.lang.NullPointerException As you can see: in 2 and 4 host is null, but we throw different exceptions. If we assume that NPE depends on file ?= null (see 2 and 5) than it is false for the 1 case!! I would suggest not to make any changes in the URL class constructor if existed implementation of URL class works correct and passes other unit tests.

          People

          • Assignee:
            Alexei Zakharov
            Reporter:
            Ilya Okomin
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development