Index: src/test/java/tests/api/java/net/URLTest.java =================================================================== --- src/test/java/tests/api/java/net/URLTest.java (revision 428654) +++ src/test/java/tests/api/java/net/URLTest.java (working copy) @@ -1176,7 +1176,85 @@ System.setSecurityManager(null); } } + + /** + * URLStreamHandler implementation class necessary for tests. + */ + private class TestURLStreamHandler extends URLStreamHandler { + public URLConnection openConnection(URL arg0) throws IOException { + try { + return arg0.openConnection(); + } catch (Throwable e) { + return null; + } + } + } + /** + * Check NPE throwing in constructor when protocol argument is null and + * URLStreamHandler argument is initialized. + */ + public void test_ConstructorLnullLjava_lang_StringILjava_lang_StringLjava_net_URLStreamHandler(){ + TestURLStreamHandler lh = new TestURLStreamHandler(); + + try { + new URL(null, "1", 0, "file", lh); + fail("NullPointerException expected, but nothing was thrown!"); + } catch (NullPointerException e) { + // Expected NullPointerException + } catch (Exception e) { + fail("NullPointerException expected, but found: " + + e.getMessage()); + } + + } + + /** + * Check NPE throwing in constructor when protocol argument is null and + * URLStreamHandler argument is null. + */ + public void test_ConstructorLnullLjava_lang_StringILjava_lang_StringLnull(){ + try { + new URL(null, "1", 0, "file", null); + fail("NullPointerException expected, but nothing was thrown!"); + } catch (NullPointerException e) { + // Expected NullPointerException + } catch (Exception e) { + fail("NullPointerException expected, but found: " + + e.getMessage()); + } + } + + /** + * Check NPE throwing in constructor with 4 params when protocol argument is null. + */ + public void test_ConstructorLnullLjava_lang_StringILjava_lang_String(){ + try { + new URL(null, "1", 0, "file"); + fail("NullPointerException expected, but nothing was thrown!"); + } catch (NullPointerException e) { + // Expected NullPointerException + } catch (Exception e) { + fail("NullPointerException expected, but found: " + + e.getMessage()); + } + } + + /** + * Check NPE throwing in constructor with 3 params when protocol argument is null. + */ + public void test_ConstructorLnullLjava_lang_StringLjava_lang_String(){ + try { + new URL(null, "1", "file"); + fail("NullPointerException expected, but nothing was thrown!"); + } catch (NullPointerException e) { + // Expected NullPointerException + } catch (Exception e) { + fail("NullPointerException expected, but found: " + + e.getMessage()); + } + } + /** * Sets up the fixture, for example, open a network connection. This method * is called before a test is executed.