From commons-dev-return-95715-apmail-jakarta-commons-dev-archive=jakarta.apache.org@jakarta.apache.org Fri Nov 17 11:01:20 2006
Return-Path:
Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org
Received: (qmail 72785 invoked from network); 17 Nov 2006 11:01:17 -0000
Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2)
by minotaur.apache.org with SMTP; 17 Nov 2006 11:01:17 -0000
Received: (qmail 86288 invoked by uid 500); 17 Nov 2006 11:01:22 -0000
Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org
Received: (qmail 86217 invoked by uid 500); 17 Nov 2006 11:01:22 -0000
Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm
Precedence: bulk
List-Unsubscribe:
List-Help:
List-Post:
List-Id: "Jakarta Commons Developers List"
Reply-To: "Jakarta Commons Developers List"
Delivered-To: mailing list commons-dev@jakarta.apache.org
Received: (qmail 86200 invoked by uid 99); 17 Nov 2006 11:01:22 -0000
Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133)
by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Nov 2006 03:01:22 -0800
X-ASF-Spam-Status: No, hits=0.6 required=10.0
tests=NO_REAL_NAME
X-Spam-Check-By: apache.org
Received-SPF: pass (herse.apache.org: local policy)
Received: from [212.249.5.50] (HELO mailsw2.globus.ch) (212.249.5.50)
by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 17 Nov 2006 03:01:09 -0800
Received: from v0c132ns.gknet.ch (V0C132NS [172.18.2.55]) by mailsw2.globus.ch
(Clearswift SMTPRS 5.2.5) with ESMTP id for ;
Fri, 17 Nov 2006 12:00:47 +0100
In-Reply-To: <9922828.1163759862820.JavaMail.jira@brutus>
To: "Jakarta Commons Developers List"
Subject: [BEANUTILS-257] Wrapping all checked exceptions
MIME-Version: 1.0
X-Mailer: Lotus Notes Release 6.5 September 26, 2003
Message-ID:
From: Aaron.Digulla@Globus.ch
Date: Fri, 17 Nov 2006 12:00:43 +0100
X-MIMETrack: Serialize by Router on V0C132NS/Globus-Gruppe(Release 6.5.4FP2|September 12, 2005) at
17.11.2006 12:00:47,
Serialize complete at 17.11.2006 12:00:47
Content-Type: text/plain; charset="US-ASCII"
X-Virus-Checked: Checked by ClamAV on apache.org
Hello,
I'd like to start the discussion about
http://issues.apache.org/jira/browse/BEANUTILS-257 which I opened.
The idea behind the issue came from using Spring and Hibernate. These big
frameworks frown upon using checked exceptions because experience shows
that the code which calls a method in the framework is rarely able to
handle the exceptions directly. Usually, you either have to pass the
exception on (adding numerous throws clauses to the code which nobody
wants except the Java compiler) or you retreat to the dreaded empty-catch,
or, even worse, to e.printStackTrace().
I have now created the patch. The patch itself is pretty small and simple
(I was surprised myself; it took less than an hour to write and test):
- I added four exception classes which are derived from RuntimeException.
They are named after the exception they are supposed to wrap (for example,
IllegalAccessException, NoSuchMethodException, etc).
- Then I simply imported these in the header of each file where the
checked exception is used. This overwrites the checked exception in the
file.
- Lastly, I had to catch the checked exception in a few places (5, IIRC)
and wrap them
Other things in the patch:
- I've moved invokeMethod() from PropertyUtilsBean to MethodUtils and made
it public static because it's a very useful function (especially with the
additional error handling).
- I've made the two private constants in ConstructorUtils public because
they are very useful elsewhere. Not strictly necessary, though.
The net result is that you can now use all methods in BeanUtils without
having to throw or catch any exception.
Except ... well, there's an unresolved issue in MappedPropertyDescriptor.
This class extends PropertyDescriptor which throws a checked exception in
the constructor (IntrospectionException) which can't be wrapped. I'm not
sure how this could be solved (or if at all).
For those who are interested, I've attached the patch to my JIRA entry so
you can have a look yourself.
To port old code to the new API, you just have to remove the import of
java.lang.reflect.InvocationTargetException and add these lines:
import org.apache.commons.beanutils.exceptions.IllegalAccessException;
import org.apache.commons.beanutils.exceptions.InstantiationException;
import org.apache.commons.beanutils.exceptions.InvocationTargetException;
import org.apache.commons.beanutils.exceptions.NoSuchMethodException;
That's it. Another solution is to remove all try/catch/throws, of course.
Best regards,
--
Aaron Digulla
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org