harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mark Hindess (JIRA)" <j...@apache.org>
Subject [jira] Closed: (HARMONY-1131) [classlib][luni]Compatibility:java.net.URL(null, String, int, String, URLStreamHandler) does not throw NPE if protocol==null
Date Tue, 29 Aug 2006 19:15:23 GMT
     [ 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

        

Mime
View raw message