You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2012/09/01 17:27:51 UTC
[codec] RuntimeException DigestUtils.getDigest(String)
There is a nice bit of (IMO) ugliness in
org.apache.commons.codec.digest.DigestUtils.getDigest(String):
public static MessageDigest getDigest(String algorithm) {
try {
return MessageDigest.getInstance(algorithm);
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException(e.getMessage());
}
}
Throwing a RuntimeException and not even linking the exception combine for
two no-nos.
I propose:
throw new IllegalArgumentException(e);
In theory, this would break someone looking for a DigestUtils throwing a
RuntimeException.
At the very least we should do:
// ugly
throw new RuntimeException(e);
Thoughts?
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: [codec] RuntimeException DigestUtils.getDigest(String)
Posted by Gary Gregory <ga...@gmail.com>.
Fixed in trunk, see Jira [CODEC-155].
Gary
On Sun, Sep 2, 2012 at 7:36 AM, sebb <se...@gmail.com> wrote:
> On 1 September 2012 17:08, Christian Hammers <ch...@lathspell.de> wrote:
> > Linking the exceptions is a good idea as it preserves the original
> > stack trace. What could cause this Exception is hard to guess but
> > a wrong paramter string is more likely than a broken Java installation
> > thus IllegalArgument probably fits better.
>
> Agreed.
>
> > bye,
> >
> > -christian-
> >
> >
> > Am Sat, 1 Sep 2012 11:27:51 -0400
> > schrieb Gary Gregory <ga...@gmail.com>:
> >
> >> There is a nice bit of (IMO) ugliness in
> >> org.apache.commons.codec.digest.DigestUtils.getDigest(String):
> >>
> >> public static MessageDigest getDigest(String algorithm) {
> >> try {
> >> return MessageDigest.getInstance(algorithm);
> >> } catch (NoSuchAlgorithmException e) {
> >> throw new RuntimeException(e.getMessage());
> >> }
> >> }
> >>
> >> Throwing a RuntimeException and not even linking the exception
> >> combine for two no-nos.
> >>
> >> I propose:
> >>
> >> throw new IllegalArgumentException(e);
> >>
> >> In theory, this would break someone looking for a DigestUtils
> >> throwing a RuntimeException.
> >>
> >> At the very least we should do:
> >>
> >> // ugly
> >> throw new RuntimeException(e);
> >>
> >> Thoughts?
> >>
> >> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> >> JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
> >> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
> >> Blog: http://garygregory.wordpress.com
> >> Home: http://garygregory.com/
> >> Tweet! http://twitter.com/GaryGregory
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> > For additional commands, e-mail: dev-help@commons.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: [codec] RuntimeException DigestUtils.getDigest(String)
Posted by sebb <se...@gmail.com>.
On 1 September 2012 17:08, Christian Hammers <ch...@lathspell.de> wrote:
> Linking the exceptions is a good idea as it preserves the original
> stack trace. What could cause this Exception is hard to guess but
> a wrong paramter string is more likely than a broken Java installation
> thus IllegalArgument probably fits better.
Agreed.
> bye,
>
> -christian-
>
>
> Am Sat, 1 Sep 2012 11:27:51 -0400
> schrieb Gary Gregory <ga...@gmail.com>:
>
>> There is a nice bit of (IMO) ugliness in
>> org.apache.commons.codec.digest.DigestUtils.getDigest(String):
>>
>> public static MessageDigest getDigest(String algorithm) {
>> try {
>> return MessageDigest.getInstance(algorithm);
>> } catch (NoSuchAlgorithmException e) {
>> throw new RuntimeException(e.getMessage());
>> }
>> }
>>
>> Throwing a RuntimeException and not even linking the exception
>> combine for two no-nos.
>>
>> I propose:
>>
>> throw new IllegalArgumentException(e);
>>
>> In theory, this would break someone looking for a DigestUtils
>> throwing a RuntimeException.
>>
>> At the very least we should do:
>>
>> // ugly
>> throw new RuntimeException(e);
>>
>> Thoughts?
>>
>> E-Mail: garydgregory@gmail.com | ggregory@apache.org
>> JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
>> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
>> Blog: http://garygregory.wordpress.com
>> Home: http://garygregory.com/
>> Tweet! http://twitter.com/GaryGregory
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org
Re: [codec] RuntimeException DigestUtils.getDigest(String)
Posted by Gary Gregory <ga...@gmail.com>.
On Sat, Sep 1, 2012 at 12:08 PM, Christian Hammers <ch...@lathspell.de> wrote:
> Linking the exceptions is a good idea as it preserves the original
> stack trace. What could cause this Exception is hard to guess but
> a wrong paramter string is more likely than a broken Java installation
> thus IllegalArgument probably fits better.
>
The BC issue in that changing to IAE breaks behavior of code like:
try {
return DigestUtils.getInstance("BadAlgorithm");
} catch (IllegalArgumentException e) {
// do somehting foo
} catch (RuntimeException e) {
// do somehting bar
}
It's unlikely but it is possible! ;)
Gary
>
> bye,
>
> -christian-
>
>
> Am Sat, 1 Sep 2012 11:27:51 -0400
> schrieb Gary Gregory <ga...@gmail.com>:
>
> > There is a nice bit of (IMO) ugliness in
> > org.apache.commons.codec.digest.DigestUtils.getDigest(String):
> >
> > public static MessageDigest getDigest(String algorithm) {
> > try {
> > return MessageDigest.getInstance(algorithm);
> > } catch (NoSuchAlgorithmException e) {
> > throw new RuntimeException(e.getMessage());
> > }
> > }
> >
> > Throwing a RuntimeException and not even linking the exception
> > combine for two no-nos.
> >
> > I propose:
> >
> > throw new IllegalArgumentException(e);
> >
> > In theory, this would break someone looking for a DigestUtils
> > throwing a RuntimeException.
> >
> > At the very least we should do:
> >
> > // ugly
> > throw new RuntimeException(e);
> >
> > Thoughts?
> >
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
> > Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>
--
E-Mail: garydgregory@gmail.com | ggregory@apache.org
JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory
Re: [codec] RuntimeException DigestUtils.getDigest(String)
Posted by Christian Hammers <ch...@lathspell.de>.
Linking the exceptions is a good idea as it preserves the original
stack trace. What could cause this Exception is hard to guess but
a wrong paramter string is more likely than a broken Java installation
thus IllegalArgument probably fits better.
bye,
-christian-
Am Sat, 1 Sep 2012 11:27:51 -0400
schrieb Gary Gregory <ga...@gmail.com>:
> There is a nice bit of (IMO) ugliness in
> org.apache.commons.codec.digest.DigestUtils.getDigest(String):
>
> public static MessageDigest getDigest(String algorithm) {
> try {
> return MessageDigest.getInstance(algorithm);
> } catch (NoSuchAlgorithmException e) {
> throw new RuntimeException(e.getMessage());
> }
> }
>
> Throwing a RuntimeException and not even linking the exception
> combine for two no-nos.
>
> I propose:
>
> throw new IllegalArgumentException(e);
>
> In theory, this would break someone looking for a DigestUtils
> throwing a RuntimeException.
>
> At the very least we should do:
>
> // ugly
> throw new RuntimeException(e);
>
> Thoughts?
>
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> JUnit in Action, 2nd Ed: <http://goog_1249600977>http://bit.ly/ECvg0
> Spring Batch in Action: <http://s.apache.org/HOq>http://bit.ly/bqpbCK
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org