Index: src/test/java/tests/api/java/net/URLConnectionTest.java =================================================================== --- src/test/java/tests/api/java/net/URLConnectionTest.java (revision 476028) +++ src/test/java/tests/api/java/net/URLConnectionTest.java (working copy) @@ -34,6 +34,7 @@ import java.net.SocketPermission; import java.net.URL; import java.net.URLConnection; +import java.net.URLStreamHandler; import java.security.Permission; import java.util.Calendar; import java.util.GregorianCalendar; @@ -838,6 +839,43 @@ assertNull("Wrong property returned: " + uc.getRequestProperty("No"), uc.getRequestProperty("No")); } + + /** + * @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"); + assertNull(urlCon.getRequestProperty("test")); + + urlCon.connect(); + try { + urlCon.getRequestProperty("test"); + fail("should throw IllegalStateException"); + } catch (IllegalStateException e) { + // expected + } + } /** * @tests java.net.URLConnection#getURL() Index: src/main/java/java/net/URLConnection.java =================================================================== --- src/main/java/java/net/URLConnection.java (revision 476028) +++ src/main/java/java/net/URLConnection.java (working copy) @@ -648,14 +648,19 @@ * @param field * the field to get the property for * @return the field to look up + * @throws IllegalStateException - + * if connection already established * * @see #getDefaultRequestProperty * @see #setDefaultRequestProperty * @see #setRequestProperty */ - public String getRequestProperty(String field) { - return null; - } + public String getRequestProperty(String field) { + if (this.connected == true) { + throw new IllegalStateException(Msg.getString("K0037")); //$NON-NLS-1$ + } + return null; + } /** * Answers the URL of this connection