Return-Path: Delivered-To: apmail-incubator-harmony-commits-archive@www.apache.org Received: (qmail 57538 invoked from network); 2 Nov 2006 12:53:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Nov 2006 12:53:08 -0000 Received: (qmail 90514 invoked by uid 500); 2 Nov 2006 12:53:19 -0000 Delivered-To: apmail-incubator-harmony-commits-archive@incubator.apache.org Received: (qmail 90487 invoked by uid 500); 2 Nov 2006 12:53:19 -0000 Mailing-List: contact harmony-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: harmony-dev@incubator.apache.org Delivered-To: mailing list harmony-commits@incubator.apache.org Received: (qmail 90476 invoked by uid 99); 2 Nov 2006 12:53:19 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Nov 2006 04:53:19 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Nov 2006 04:53:04 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 404701A9846; Thu, 2 Nov 2006 04:52:40 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: harmony-commits@incubator.apache.org From: pyang@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061102125240.404701A9846@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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> 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 {