Index: src/test/java/tests/api/java/net/URLConnectionTest.java =================================================================== --- src/test/java/tests/api/java/net/URLConnectionTest.java (revision 482869) +++ src/test/java/tests/api/java/net/URLConnectionTest.java (working copy) @@ -382,6 +382,22 @@ } } + + /** + * @tests java.net.URLConnection#getRequestProperties() + */ + public void test_getRequestProperties_Exception() throws IOException { + URL url = new URL("http", "test", 80, "index.html", new NewHandler()); + URLConnection urlCon = url.openConnection(); + urlCon.connect(); + + try { + urlCon.getRequestProperties(); + fail("should throw IllegalStateException"); + } catch (IllegalStateException e) { + // expected + } + } /** * @tests java.net.URLConnection#getHeaderField(java.lang.String) @@ -844,25 +860,6 @@ * @tests java.net.URLConnection#getRequestProperty(java.lang.String) */ public void test_getRequestProperty_LString_Exception() throws IOException { - class NewHandler extends URLStreamHandler { - protected URLConnection openConnection(URL u) - throws java.io.IOException { - return new HttpURLConnection(u) { - @Override - public void disconnect() { - // do nothing - } - @Override - public boolean usingProxy() { - return false; - } - @Override - public void connect() throws IOException { - connected = true; - } - }; - } - } URL url = new URL("http", "test", 80, "index.html", new NewHandler()); URLConnection urlCon = url.openConnection(); urlCon.setRequestProperty("test", "testProperty"); @@ -1077,3 +1074,24 @@ ((HttpURLConnection) uc).disconnect(); } } + +class NewHandler extends URLStreamHandler { + protected URLConnection openConnection(URL u) throws java.io.IOException { + return new HttpURLConnection(u) { + @Override + public void disconnect() { + // do nothing + } + + @Override + public boolean usingProxy() { + return false; + } + + @Override + public void connect() throws IOException { + connected = true; + } + }; + } +} Index: src/main/java/java/net/URLConnection.java =================================================================== --- src/main/java/java/net/URLConnection.java (revision 482869) +++ src/main/java/java/net/URLConnection.java (working copy) @@ -445,6 +445,9 @@ * @since 1.4 */ public Map> getRequestProperties() { + if (connected) { + throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$ + } return Collections.emptyMap(); } @@ -656,7 +659,7 @@ * @see #setRequestProperty */ public String getRequestProperty(String field) { - if (this.connected == true) { + if (connected) { throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$ } return null;