Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 25717 invoked from network); 8 Jan 2007 15:00:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 8 Jan 2007 15:00:07 -0000 Received: (qmail 76893 invoked by uid 500); 8 Jan 2007 15:00:14 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 76301 invoked by uid 500); 8 Jan 2007 15:00:12 -0000 Mailing-List: contact dev-help@harmony.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@harmony.apache.org Delivered-To: mailing list dev@harmony.apache.org Received: (qmail 76292 invoked by uid 99); 8 Jan 2007 15:00:12 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jan 2007 07:00:12 -0800 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (herse.apache.org: domain of zhanghuangzhu@gmail.com designates 64.233.182.190 as permitted sender) Received: from [64.233.182.190] (HELO nf-out-0910.google.com) (64.233.182.190) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Jan 2007 07:00:03 -0800 Received: by nf-out-0910.google.com with SMTP id a4so9276514nfc for ; Mon, 08 Jan 2007 06:59:41 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=ag2Um0OFvfAoI1OQP6mR8HdAlRtudXriJ75UYfqmlbk4h4dDf8CoUZeguBQdJ71iMGAPdJRGvlmeGh+kJRUyQ/DPY6RFgjkgN9LI9VZ7WIUWmMs+ROycAKtP5yJ7mfRBgsKbGvlV7XD6IAl2j4orvdb07k95ow6DLLN81R9qfMY= Received: by 10.82.105.13 with SMTP id d13mr2568838buc.1168268381396; Mon, 08 Jan 2007 06:59:41 -0800 (PST) Received: by 10.82.112.18 with HTTP; Mon, 8 Jan 2007 06:59:41 -0800 (PST) Message-ID: <4d0b24970701080659v3112090dl26686b6c577e594c@mail.gmail.com> Date: Mon, 8 Jan 2007 22:59:41 +0800 From: "Andrew Zhang" To: dev@harmony.apache.org Subject: Re: [classlib] [luni] Ignored Exceptions and HARMONY-2939 In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_72650_30830680.1168268381367" References: X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_72650_30830680.1168268381367 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 1/8/07, Sian January wrote: > Hello everyone, > > I have recently been looking at ignored Exceptions in luni (i.e. places > where an Exception is caught but the catch block is empty). These are > generally a bad idea because if an Exception does occur it is lost - the > user doesn't see it and it's not logged anywhere either, so if it causes a > problem in the program it is very difficult to find the root cause. > > I would like to discuss one of these in particular, in > URLCLassLoader.findResources where an IOException and a > SecurityException are ignored. Since the signature of the method says > that > it throws an IOException (and SecurityException is a subtype of > RuntimeException) I thought the try-catch block could probably be removed > entirely. However it is an API method and I am finding it difficult to > write a test case for this because I'm not sure how to force either of > those > Exceptions. > > Geir suggested it might be an interesting topic for the mailing list so > please post your thoughts. Also if anyone knows how to write the test > case > that would be especially helpful. I think it's not difficult to write test cases for SecurityException. Write a specific security manager and set it as system security manager. For this case, the source code is as follow: try { sm.checkPermission(result.openConnection().getPermission()); } catch (IOException e) { return null; } catch (SecurityException e) { return null; } So it's easy to mock a security manager to disable "result.openConnection().getPermission()", and write a test to see whether RI returns silently or throws a security exception. There're many similar tests already in luni module. You may take a look at SocketTest#test_ConstructorLjava_net_Proxy_Exception() for reference. IOException is a bit complicated, maybe you need to mock more things. :-) > Details at > https://issues.apache.org/jira/browse/HARMONY-2939. > > Thanks, > > Sian > > -- > Sian January > > IBM Java Technology Centre, UK > > -- Best regards, Andrew Zhang ------=_Part_72650_30830680.1168268381367--