You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Ilya Okomin (JIRA)" <ji...@apache.org> on 2006/08/10 10:12:16 UTC

[jira] Created: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null

[classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
----------------------------------------------------------------------------------------------------------------------------

                 Key: HARMONY-1131
                 URL: http://issues.apache.org/jira/browse/HARMONY-1131
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Ilya Okomin
            Priority: Trivial
         Attachments: URL.patch, URLTest.patch

RI throws unspecified NPE for java.net.URL(null, String, int, String, URLStreamHandler) while Harmony does not.
For java.net.URL(null, String, int, String) method both RI and Harmopny throw NPE.

Actually, java.net.URL(URL context, String spec) constructor accrording to the spec must throw "MalformedURLException - if no protocol is specified, or an unknown protocol is found." Thus it can be assumed that if protocol undefined for other URL constructors with protocol as an argument we have to throw MalformedURLException. However the spec is keep silence about that and RI throws only NullPointerException for such cases (see the test sample code and output). For this reason for these undocumented cases it makes sence to throw NPE with exploratory message if no protocol specified to be compatible with RI behavior.

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

public class test {

    public static void main(String[] args) throws Exception{
        
        try {
            System.err.print("5 params : ");
            TestURLStreamHandler lh = new TestURLStreamHandler();
            new URL(null, "1", 0, "file", lh);
            System.err.println("error: NPE wasn't thrown!");
        } catch (Exception e) {
            System.err.println("success");
            e.printStackTrace();
        }

        try {
            System.err.print("5 params (handler null): ");
            new URL(null, "1", 0, "file", null);
            System.err.println("error: NPE wasn't thrown!");
        } catch (Exception e) {
            System.err.println("success");
            e.printStackTrace();
        }

        try {
            System.err.print("4 params : ");
            new URL(null, "1", 0, "file");
            System.err.println("error: NPE wasn't thrown!");
        } catch (Exception e) {
            System.err.println("success");
            e.printStackTrace();
        }
        
        try {
            System.err.print("3 params : ");
            new URL(null, "1", "file");
            System.err.println("error: NPE wasn't thrown!");
        } catch (Exception e) {
            System.err.println("success");
            e.printStackTrace();
        }

    }
}

class TestURLStreamHandler extends URLStreamHandler {
    public URLConnection openConnection(URL arg0) throws IOException {
        try {
            return arg0.openConnection();
        } catch (Throwable e) {
            return null;
        }
    }
}

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

Output: 

Harmony: 
java version "1.5.0" 
pre-alpha : not complete or compatible 
svn = r424571, (Jul 22 2006), Windows/ia32/msvc 1310, release build 
http://incubator.apache.org/harmony 

5 params : error: NPE wasn't thrown!
5 params (handler null): success
java.lang.NullPointerException
	at java.util.Hashtable.get(Hashtable.java:524)
	at java.net.URL.setupStreamHandler(URL.java:554)
	at java.net.URL.<init>(URL.java:421)
	at bugzilla.Test9449.main(Test9449.java:22)
4 params : success
java.lang.NullPointerException
	at java.util.Hashtable.get(Hashtable.java:524)
	at java.net.URL.setupStreamHandler(URL.java:554)
	at java.net.URL.<init>(URL.java:421)
	at java.net.URL.<init>(URL.java:367)
	at bugzilla.Test9449.main(Test9449.java:31)
3 params : success
java.lang.NullPointerException
	at java.util.Hashtable.get(Hashtable.java:524)
	at java.net.URL.setupStreamHandler(URL.java:554)
	at java.net.URL.<init>(URL.java:421)
	at java.net.URL.<init>(URL.java:347)
	at bugzilla.Test9449.main(Test9449.java:40)

RI: 
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)) 

5 params : success
java.lang.NullPointerException
	at java.net.URL.<init>(URL.java:358)
	at bugzilla.Test9449.main(Test9449.java:13)
5 params (handler null): success
java.lang.NullPointerException
	at java.net.URL.<init>(URL.java:358)
	at bugzilla.Test9449.main(Test9449.java:22)
4 params : success
java.lang.NullPointerException
	at java.net.URL.<init>(URL.java:358)
	at java.net.URL.<init>(URL.java:283)
	at bugzilla.Test9449.main(Test9449.java:31)
3 params : success
java.lang.NullPointerException
	at java.net.URL.<init>(URL.java:358)
	at java.net.URL.<init>(URL.java:283)
	at java.net.URL.<init>(URL.java:306)
	at bugzilla.Test9449.main(Test9449.java:40)

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

Suggested patch and unit test could be found in attach.


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Closed: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null

Posted by "Mark Hindess (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-1131?page=all ]

Mark Hindess closed HARMONY-1131.
---------------------------------

    Assignee: Mark Hindess

Verified by Ilya.


> [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1131
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1131
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Ilya Okomin
>         Assigned To: Mark Hindess
>            Priority: Trivial
>         Attachments: URL.patch, URL.patch, URLTest.patch, URLTest.patch
>
>
> RI throws unspecified NPE for java.net.URL(null, String, int, String, URLStreamHandler) while Harmony does not.
> For java.net.URL(null, String, int, String) method both RI and Harmopny throw NPE.
> Actually, java.net.URL(URL context, String spec) constructor accrording to the spec must throw "MalformedURLException - if no protocol is specified, or an unknown protocol is found." Thus it can be assumed that if protocol undefined for other URL constructors with protocol as an argument we have to throw MalformedURLException. However the spec is keep silence about that and RI throws only NullPointerException for such cases (see the test sample code and output). For this reason for these undocumented cases it makes sence to throw NPE with exploratory message if no protocol specified to be compatible with RI behavior.
> =================test.java================
> import java.net.*;
> import java.io.*;
> public class test {
>     public static void main(String[] args) throws Exception{
>         
>         try {
>             System.err.print("5 params : ");
>             TestURLStreamHandler lh = new TestURLStreamHandler();
>             new URL(null, "1", 0, "file", lh);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("5 params (handler null): ");
>             new URL(null, "1", 0, "file", null);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("4 params : ");
>             new URL(null, "1", 0, "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         
>         try {
>             System.err.print("3 params : ");
>             new URL(null, "1", "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>     }
> }
> class TestURLStreamHandler extends URLStreamHandler {
>     public URLConnection openConnection(URL arg0) throws IOException {
>         try {
>             return arg0.openConnection();
>         } catch (Throwable e) {
>             return null;
>         }
>     }
> }
> =============================================
> Output: 
> Harmony: 
> java version "1.5.0" 
> pre-alpha : not complete or compatible 
> svn = r424571, (Jul 22 2006), Windows/ia32/msvc 1310, release build 
> http://incubator.apache.org/harmony 
> 5 params : error: NPE wasn't thrown!
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:367)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:347)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> RI: 
> 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)) 
> 5 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:13)
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at java.net.URL.<init>(URL.java:306)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> =======================================
> Suggested patch and unit test could be found in attach.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Resolved: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null

Posted by "Mark Hindess (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-1131?page=all ]

Mark Hindess resolved HARMONY-1131.
-----------------------------------

    Resolution: Fixed

Applied in r438075.  I modified the tests slightly to handle the exceptional exception cases using the convention preferred by the project. 

Ilya, please confirm that the patches have been applied as you expect.  Thanks.


> [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1131
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1131
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Ilya Okomin
>            Priority: Trivial
>         Attachments: URL.patch, URL.patch, URLTest.patch, URLTest.patch
>
>
> RI throws unspecified NPE for java.net.URL(null, String, int, String, URLStreamHandler) while Harmony does not.
> For java.net.URL(null, String, int, String) method both RI and Harmopny throw NPE.
> Actually, java.net.URL(URL context, String spec) constructor accrording to the spec must throw "MalformedURLException - if no protocol is specified, or an unknown protocol is found." Thus it can be assumed that if protocol undefined for other URL constructors with protocol as an argument we have to throw MalformedURLException. However the spec is keep silence about that and RI throws only NullPointerException for such cases (see the test sample code and output). For this reason for these undocumented cases it makes sence to throw NPE with exploratory message if no protocol specified to be compatible with RI behavior.
> =================test.java================
> import java.net.*;
> import java.io.*;
> public class test {
>     public static void main(String[] args) throws Exception{
>         
>         try {
>             System.err.print("5 params : ");
>             TestURLStreamHandler lh = new TestURLStreamHandler();
>             new URL(null, "1", 0, "file", lh);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("5 params (handler null): ");
>             new URL(null, "1", 0, "file", null);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("4 params : ");
>             new URL(null, "1", 0, "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         
>         try {
>             System.err.print("3 params : ");
>             new URL(null, "1", "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>     }
> }
> class TestURLStreamHandler extends URLStreamHandler {
>     public URLConnection openConnection(URL arg0) throws IOException {
>         try {
>             return arg0.openConnection();
>         } catch (Throwable e) {
>             return null;
>         }
>     }
> }
> =============================================
> Output: 
> Harmony: 
> java version "1.5.0" 
> pre-alpha : not complete or compatible 
> svn = r424571, (Jul 22 2006), Windows/ia32/msvc 1310, release build 
> http://incubator.apache.org/harmony 
> 5 params : error: NPE wasn't thrown!
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:367)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:347)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> RI: 
> 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)) 
> 5 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:13)
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at java.net.URL.<init>(URL.java:306)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> =======================================
> Suggested patch and unit test could be found in attach.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Commented: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null

Posted by "Ilya Okomin (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/HARMONY-1131?page=comments#action_12431269 ] 
            
Ilya Okomin commented on HARMONY-1131:
--------------------------------------

Mark, thanks for tests modification, unfortunately I read aboud exceptions handling in tests a bit later than uploaded this patch.
Patches looks fine for me.

> [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1131
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1131
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Ilya Okomin
>            Priority: Trivial
>         Attachments: URL.patch, URL.patch, URLTest.patch, URLTest.patch
>
>
> RI throws unspecified NPE for java.net.URL(null, String, int, String, URLStreamHandler) while Harmony does not.
> For java.net.URL(null, String, int, String) method both RI and Harmopny throw NPE.
> Actually, java.net.URL(URL context, String spec) constructor accrording to the spec must throw "MalformedURLException - if no protocol is specified, or an unknown protocol is found." Thus it can be assumed that if protocol undefined for other URL constructors with protocol as an argument we have to throw MalformedURLException. However the spec is keep silence about that and RI throws only NullPointerException for such cases (see the test sample code and output). For this reason for these undocumented cases it makes sence to throw NPE with exploratory message if no protocol specified to be compatible with RI behavior.
> =================test.java================
> import java.net.*;
> import java.io.*;
> public class test {
>     public static void main(String[] args) throws Exception{
>         
>         try {
>             System.err.print("5 params : ");
>             TestURLStreamHandler lh = new TestURLStreamHandler();
>             new URL(null, "1", 0, "file", lh);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("5 params (handler null): ");
>             new URL(null, "1", 0, "file", null);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("4 params : ");
>             new URL(null, "1", 0, "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         
>         try {
>             System.err.print("3 params : ");
>             new URL(null, "1", "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>     }
> }
> class TestURLStreamHandler extends URLStreamHandler {
>     public URLConnection openConnection(URL arg0) throws IOException {
>         try {
>             return arg0.openConnection();
>         } catch (Throwable e) {
>             return null;
>         }
>     }
> }
> =============================================
> Output: 
> Harmony: 
> java version "1.5.0" 
> pre-alpha : not complete or compatible 
> svn = r424571, (Jul 22 2006), Windows/ia32/msvc 1310, release build 
> http://incubator.apache.org/harmony 
> 5 params : error: NPE wasn't thrown!
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:367)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:347)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> RI: 
> 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)) 
> 5 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:13)
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at java.net.URL.<init>(URL.java:306)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> =======================================
> Suggested patch and unit test could be found in attach.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null

Posted by "Ilya Okomin (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-1131?page=all ]

Ilya Okomin updated HARMONY-1131:
---------------------------------

    Attachment: URLTest.patch

test patch with granted license for ASF 

> [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1131
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1131
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Ilya Okomin
>            Priority: Trivial
>         Attachments: URL.patch, URL.patch, URLTest.patch, URLTest.patch
>
>
> RI throws unspecified NPE for java.net.URL(null, String, int, String, URLStreamHandler) while Harmony does not.
> For java.net.URL(null, String, int, String) method both RI and Harmopny throw NPE.
> Actually, java.net.URL(URL context, String spec) constructor accrording to the spec must throw "MalformedURLException - if no protocol is specified, or an unknown protocol is found." Thus it can be assumed that if protocol undefined for other URL constructors with protocol as an argument we have to throw MalformedURLException. However the spec is keep silence about that and RI throws only NullPointerException for such cases (see the test sample code and output). For this reason for these undocumented cases it makes sence to throw NPE with exploratory message if no protocol specified to be compatible with RI behavior.
> =================test.java================
> import java.net.*;
> import java.io.*;
> public class test {
>     public static void main(String[] args) throws Exception{
>         
>         try {
>             System.err.print("5 params : ");
>             TestURLStreamHandler lh = new TestURLStreamHandler();
>             new URL(null, "1", 0, "file", lh);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("5 params (handler null): ");
>             new URL(null, "1", 0, "file", null);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("4 params : ");
>             new URL(null, "1", 0, "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         
>         try {
>             System.err.print("3 params : ");
>             new URL(null, "1", "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>     }
> }
> class TestURLStreamHandler extends URLStreamHandler {
>     public URLConnection openConnection(URL arg0) throws IOException {
>         try {
>             return arg0.openConnection();
>         } catch (Throwable e) {
>             return null;
>         }
>     }
> }
> =============================================
> Output: 
> Harmony: 
> java version "1.5.0" 
> pre-alpha : not complete or compatible 
> svn = r424571, (Jul 22 2006), Windows/ia32/msvc 1310, release build 
> http://incubator.apache.org/harmony 
> 5 params : error: NPE wasn't thrown!
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:367)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:347)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> RI: 
> 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)) 
> 5 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:13)
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at java.net.URL.<init>(URL.java:306)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> =======================================
> Suggested patch and unit test could be found in attach.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] Updated: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null

Posted by "Ilya Okomin (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/HARMONY-1131?page=all ]

Ilya Okomin updated HARMONY-1131:
---------------------------------

    Attachment: URL.patch

patch with granted license for ASF

> [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
> ----------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-1131
>                 URL: http://issues.apache.org/jira/browse/HARMONY-1131
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>            Reporter: Ilya Okomin
>            Priority: Trivial
>         Attachments: URL.patch, URL.patch, URLTest.patch
>
>
> RI throws unspecified NPE for java.net.URL(null, String, int, String, URLStreamHandler) while Harmony does not.
> For java.net.URL(null, String, int, String) method both RI and Harmopny throw NPE.
> Actually, java.net.URL(URL context, String spec) constructor accrording to the spec must throw "MalformedURLException - if no protocol is specified, or an unknown protocol is found." Thus it can be assumed that if protocol undefined for other URL constructors with protocol as an argument we have to throw MalformedURLException. However the spec is keep silence about that and RI throws only NullPointerException for such cases (see the test sample code and output). For this reason for these undocumented cases it makes sence to throw NPE with exploratory message if no protocol specified to be compatible with RI behavior.
> =================test.java================
> import java.net.*;
> import java.io.*;
> public class test {
>     public static void main(String[] args) throws Exception{
>         
>         try {
>             System.err.print("5 params : ");
>             TestURLStreamHandler lh = new TestURLStreamHandler();
>             new URL(null, "1", 0, "file", lh);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("5 params (handler null): ");
>             new URL(null, "1", 0, "file", null);
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         try {
>             System.err.print("4 params : ");
>             new URL(null, "1", 0, "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>         
>         try {
>             System.err.print("3 params : ");
>             new URL(null, "1", "file");
>             System.err.println("error: NPE wasn't thrown!");
>         } catch (Exception e) {
>             System.err.println("success");
>             e.printStackTrace();
>         }
>     }
> }
> class TestURLStreamHandler extends URLStreamHandler {
>     public URLConnection openConnection(URL arg0) throws IOException {
>         try {
>             return arg0.openConnection();
>         } catch (Throwable e) {
>             return null;
>         }
>     }
> }
> =============================================
> Output: 
> Harmony: 
> java version "1.5.0" 
> pre-alpha : not complete or compatible 
> svn = r424571, (Jul 22 2006), Windows/ia32/msvc 1310, release build 
> http://incubator.apache.org/harmony 
> 5 params : error: NPE wasn't thrown!
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:367)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.util.Hashtable.get(Hashtable.java:524)
> 	at java.net.URL.setupStreamHandler(URL.java:554)
> 	at java.net.URL.<init>(URL.java:421)
> 	at java.net.URL.<init>(URL.java:347)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> RI: 
> 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)) 
> 5 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:13)
> 5 params (handler null): success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at bugzilla.Test9449.main(Test9449.java:22)
> 4 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at bugzilla.Test9449.main(Test9449.java:31)
> 3 params : success
> java.lang.NullPointerException
> 	at java.net.URL.<init>(URL.java:358)
> 	at java.net.URL.<init>(URL.java:283)
> 	at java.net.URL.<init>(URL.java:306)
> 	at bugzilla.Test9449.main(Test9449.java:40)
> =======================================
> Suggested patch and unit test could be found in attach.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira