Return-Path: Delivered-To: apmail-harmony-dev-archive@www.apache.org Received: (qmail 87136 invoked from network); 13 Nov 2009 23:20:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 13 Nov 2009 23:20:37 -0000 Received: (qmail 32463 invoked by uid 500); 13 Nov 2009 23:20:37 -0000 Delivered-To: apmail-harmony-dev-archive@harmony.apache.org Received: (qmail 32385 invoked by uid 500); 13 Nov 2009 23:20:37 -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 32373 invoked by uid 99); 13 Nov 2009 23:20:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2009 23:20:37 +0000 X-ASF-Spam-Status: No, hits=-6.4 required=5.0 tests=AWL,BAYES_00,HTML_MESSAGE,RCVD_IN_DNSWL_MED X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of jessewilson@google.com designates 216.239.33.17 as permitted sender) Received: from [216.239.33.17] (HELO smtp-out.google.com) (216.239.33.17) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2009 23:20:34 +0000 Received: from spaceape10.eur.corp.google.com (spaceape10.eur.corp.google.com [172.28.16.144]) by smtp-out.google.com with ESMTP id nADNKCS1010147 for ; Fri, 13 Nov 2009 23:20:13 GMT DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=google.com; s=beta; t=1258154413; bh=iK8RKgpaBJd5Qxdj+hEYvSpwPss=; h=MIME-Version:From:Date:Message-ID:Subject:To:Content-Type; b=iNvXq6wDUNZv2yk7ImM9gkTdFfnLEbb6q+YeWqdxCn8jKESlgnmo5aR7j3+mvUGNR 45kvyz3KatvWA1aJe9Exw== DomainKey-Signature: a=rsa-sha1; s=beta; d=google.com; c=nofws; q=dns; h=mime-version:from:date:message-id:subject:to:content-type:x-system-of-record; b=gvO+tDUvfEEYN2VrKzXAKuQi3ziTeFZ3melaquHM2fm1w6g1smCh+hJFQqOatt52j W4a9pRd1+JaAcz2484x5A== Received: from iwn35 (iwn35.prod.google.com [10.241.68.99]) by spaceape10.eur.corp.google.com with ESMTP id nADNK8x4024573 for ; Fri, 13 Nov 2009 15:20:09 -0800 Received: by iwn35 with SMTP id 35so3155260iwn.26 for ; Fri, 13 Nov 2009 15:20:08 -0800 (PST) MIME-Version: 1.0 Received: by 10.231.1.22 with SMTP id 22mr2257615ibd.56.1258154408082; Fri, 13 Nov 2009 15:20:08 -0800 (PST) From: Jesse Wilson Date: Fri, 13 Nov 2009 15:19:48 -0800 Message-ID: Subject: Doubting exception priority compatibility To: Harmony Dev Content-Type: multipart/alternative; boundary=00151773eaa090fe4d047848e653 X-System-Of-Record: true --00151773eaa090fe4d047848e653 Content-Type: text/plain; charset=UTF-8 Harmony team, I'm skeptical of the utility of being exception-priority compatible with the RI. We have a wiki page describes our goals, but I don't think these are worth their costs. Recently I broke tests by breaking exception priority on this code: public int read(char[] buffer, int offset, int length) throws IOException { synchronized (lock) { if (isClosed()) { throw new IOException(Msg.getString("K005b")); //$NON-NLS-1$ } if (offset < 0 || offset > buffer.length - length || length < 0) { throw new IndexOutOfBoundsException(); } ... We have test coverage that asserts the RI's exact exception priority: 1. if offset is negative, an IndexOutOfBoundsException is thrown 2. if buffer is null, a NullPointerException is thrown 3. if length is negative, an IndexOutOfBoundsException is thrown This is very compatible! But it ties our hands from making common sense improvements. For example, we cannot cache the buffer length in a local variable without disrupting exception priority. The following change reorders #1 and #2:: ... *int bufferLength = buffer.length; // cache this in a local variable* if (offset < 0 || offset > bufferLength - length || length < 0) { throw new IndexOutOfBoundsException(); } Nor can we save branching operations by using bitwise rather than logical OR. The following change reorders #2 and #3: ... if (*offset | length < 0* || offset > buffer.length - length) { throw new IndexOutOfBoundsException(); } I'm all for compatibility. But I don't believe it is in our best interest to strive for this degree of compatibility with the RI. Trying to get this level of compatibility takes engineering time away from more useful tasks. The RI's exception priorities are generally undocumented, and therefore must be reverse engineered in each case. It also requires significant effort to write test coverage for exception priorities. Although I acknowledge that much of this work has already been done, many additional APIs and revisions are still ahead of us. I don't think real-world applications depend on exception priorities. For example, I'm highly skeptical that there are programs that only work on platforms where the exceptions above are thrown with priority #1, #2, #3. I don't think I've ever seen a program that catches IndexOutOfBoundsException. In my experience applications catch either the common supertype RuntimeException, or they don't catch at all. Agree/disagree? --00151773eaa090fe4d047848e653--