harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r470356 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java test/java/tests/api/java/net/HttpURLConnectionTest.java
Date Thu, 02 Nov 2006 12:52:40 GMT
Author: pyang
Date: Thu Nov  2 04:52:39 2006
New Revision: 470356

URL: http://svn.apache.org/viewvc?view=rev&rev=470356
Log:
Apply patch for HARMONY-1687 ([classlib][net] unexpected IllegalAccessError for HttpURLConnection.getRequestProperty(String))

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java?view=diff&rev=470356&r1=470355&r2=470356
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/internal/net/www/protocol/http/HttpURLConnection.java
Thu Nov  2 04:52:39 2006
@@ -826,6 +826,9 @@
 
     @Override
     public Map<String, List<String>> getRequestProperties() {
+        if (connected) {
+            throw new IllegalStateException(Msg.getString("K0091")); //$NON-NLS-1$
+        }
         return reqHeader.getFieldMap();
     }
 
@@ -938,8 +941,8 @@
 
     @Override
     public String getRequestProperty(String field) {
-        if (connected) {
-            throw new IllegalAccessError(Msg.getString("K0091"));
+        if (null == field) {
+            return null;
         }
         return reqHeader.get(field);
     }
@@ -1215,7 +1218,7 @@
     @Override
     public void setRequestProperty(String field, String newValue) {
         if (connected) {
-            throw new IllegalAccessError(Msg.getString("K0092"));
+            throw new IllegalStateException(Msg.getString("K0092"));
         }
         if (field == null) {
             throw new NullPointerException();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java?view=diff&rev=470356&r1=470355&r2=470356
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/net/HttpURLConnectionTest.java
Thu Nov  2 04:52:39 2006
@@ -24,6 +24,7 @@
 import java.net.CacheResponse;
 import java.net.ConnectException;
 import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
 import java.net.ResponseCache;
 import java.net.URI;
 import java.net.URL;
@@ -136,10 +137,64 @@
 		} catch (UnsupportedOperationException e) {
 		}
 	}
-
+    
+    /**
+     * @tests java.net.HttpURLConnection#getRequestProperty(String)
+     */
+    public void test_getRequestPropertyLjava_lang_String_BeforeConnected()
+            throws MalformedURLException, IOException {
+        uc.setRequestProperty("whatever", "you like"); //$NON-NLS-1$//$NON-NLS-2$
+        String res = uc.getRequestProperty("whatever"); //$NON-NLS-1$
+        assertEquals("you like", res); //$NON-NLS-1$
+
+        uc.setRequestProperty("", "you like"); //$NON-NLS-1$//$NON-NLS-2$
+        res = uc.getRequestProperty(""); //$NON-NLS-1$
+        assertEquals("you like", res); //$NON-NLS-1$
+
+        uc.setRequestProperty("", null); //$NON-NLS-1$
+        res = uc.getRequestProperty(""); //$NON-NLS-1$
+        assertEquals(null, res);
+        try {
+            uc.setRequestProperty(null, "you like"); //$NON-NLS-1$
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+    }
+    
+    /**
+     * @tests java.net.HttpURLConnection#getRequestProperty(String)
+     */
+    public void test_getRequestPropertyLjava_lang_String_AfterConnected()
+            throws IOException {
+        uc.connect();
+        try {
+            uc.setRequestProperty("whatever", "you like"); //$NON-NLS-1$//$NON-NLS-2$
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch (IllegalStateException e) {
+            // expected
+        }
+        try {
+            uc.setRequestProperty(null, "you like"); //$NON-NLS-1$
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch (IllegalStateException e) {
+            // expected
+        }
+        String res = uc.getRequestProperty("whatever"); //$NON-NLS-1$
+        assertEquals(null, res);
+        res = uc.getRequestProperty(null);
+        assertEquals(null, res);
+        try {
+            uc.getRequestProperties();
+            fail("Should throw IllegalStateException"); //$NON-NLS-1$
+        } catch (IllegalStateException e) {
+            // expected
+        }
+    }
+    
 	/**
-	 * @tests java.net.HttpURLConnection#usingProxy()
-	 */
+     * @tests java.net.HttpURLConnection#usingProxy()
+     */
 	public void test_usingProxy() {
 		try {
 			try {



Mime
View raw message