You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by li...@apache.org on 2006/12/06 07:51:36 UTC

svn commit: r482927 - in /harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/URLConnection.java test/java/tests/api/java/net/URLConnectionTest.java

Author: liangyx
Date: Tue Dec  5 22:51:35 2006
New Revision: 482927

URL: http://svn.apache.org/viewvc?view=rev&rev=482927
Log:
Apply patch for HARMONY-2480 ([classlib][luni]URLConnection's method getRequestProperties should throw IllegalStateException if already connected)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java?view=diff&rev=482927&r1=482926&r2=482927
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/net/URLConnection.java Tue Dec  5 22:51:35 2006
@@ -445,6 +445,9 @@
 	 * @since 1.4
 	 */
 	public Map<String, List<String>> 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;

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java?view=diff&rev=482927&r1=482926&r2=482927
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/URLConnectionTest.java Tue Dec  5 22:51:35 2006
@@ -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");
@@ -1076,4 +1073,25 @@
 	protected void tearDown() {
 		((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;
+            }
+        };
+    }
 }