You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2014/08/28 06:28:25 UTC
svn commit: r1621034 -
/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
Author: mattsicker
Date: Thu Aug 28 04:28:25 2014
New Revision: 1621034
URL: http://svn.apache.org/r1621034
Log:
Simplify null check. The string is never nul.
Modified:
logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
Modified: logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java?rev=1621034&r1=1621033&r2=1621034&view=diff
==============================================================================
--- logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java (original)
+++ logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java Thu Aug 28 04:28:25 2014
@@ -178,13 +178,11 @@ public final class OptionConverter {
multiplier = ONE_K * ONE_K * ONE_K;
str = str.substring(0, index);
}
- if (str != null) {
- try {
- return Long.parseLong(str) * multiplier;
- } catch (final NumberFormatException e) {
- LOGGER.error("[{}] is not in proper int form.", str);
- LOGGER.error("[{}] not in expected format.", value, e);
- }
+ try {
+ return Long.parseLong(str) * multiplier;
+ } catch (final NumberFormatException e) {
+ LOGGER.error("[{}] is not in proper int form.", str);
+ LOGGER.error("[{}] not in expected format.", value, e);
}
return defaultValue;
}
Re: svn commit: r1621034 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
Posted by Matt Sicker <bo...@gmail.com>.
Literally the only exception that's possible there is
NumberFormatException, but I do agree in principle.
On 28 August 2014 01:56, Remko Popma <re...@gmail.com> wrote:
> Just looking at that code snippet I'm thinking it would be more robust to
> just catch and log any exception here, instead of just NumberFormatEx...
> Then it doesn't matter if later code changes make it possible for str to be
> null again.
>
>
> On Thu, Aug 28, 2014 at 1:28 PM, <ma...@apache.org> wrote:
>
>> Author: mattsicker
>> Date: Thu Aug 28 04:28:25 2014
>> New Revision: 1621034
>>
>> URL: http://svn.apache.org/r1621034
>> Log:
>> Simplify null check. The string is never nul.
>>
>> Modified:
>>
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
>>
>> Modified:
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
>> URL:
>> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java?rev=1621034&r1=1621033&r2=1621034&view=diff
>>
>> ==============================================================================
>> ---
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
>> (original)
>> +++
>> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
>> Thu Aug 28 04:28:25 2014
>> @@ -178,13 +178,11 @@ public final class OptionConverter {
>> multiplier = ONE_K * ONE_K * ONE_K;
>> str = str.substring(0, index);
>> }
>> - if (str != null) {
>> - try {
>> - return Long.parseLong(str) * multiplier;
>> - } catch (final NumberFormatException e) {
>> - LOGGER.error("[{}] is not in proper int form.", str);
>> - LOGGER.error("[{}] not in expected format.", value, e);
>> - }
>> + try {
>> + return Long.parseLong(str) * multiplier;
>> + } catch (final NumberFormatException e) {
>> + LOGGER.error("[{}] is not in proper int form.", str);
>> + LOGGER.error("[{}] not in expected format.", value, e);
>> }
>> return defaultValue;
>> }
>>
>>
>>
>
--
Matt Sicker <bo...@gmail.com>
Re: svn commit: r1621034 - /logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
Posted by Remko Popma <re...@gmail.com>.
Just looking at that code snippet I'm thinking it would be more robust to
just catch and log any exception here, instead of just NumberFormatEx...
Then it doesn't matter if later code changes make it possible for str to be
null again.
On Thu, Aug 28, 2014 at 1:28 PM, <ma...@apache.org> wrote:
> Author: mattsicker
> Date: Thu Aug 28 04:28:25 2014
> New Revision: 1621034
>
> URL: http://svn.apache.org/r1621034
> Log:
> Simplify null check. The string is never nul.
>
> Modified:
>
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
>
> Modified:
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
> URL:
> http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java?rev=1621034&r1=1621033&r2=1621034&view=diff
>
> ==============================================================================
> ---
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
> (original)
> +++
> logging/log4j/log4j2/trunk/log4j-core/src/main/java/org/apache/logging/log4j/core/util/OptionConverter.java
> Thu Aug 28 04:28:25 2014
> @@ -178,13 +178,11 @@ public final class OptionConverter {
> multiplier = ONE_K * ONE_K * ONE_K;
> str = str.substring(0, index);
> }
> - if (str != null) {
> - try {
> - return Long.parseLong(str) * multiplier;
> - } catch (final NumberFormatException e) {
> - LOGGER.error("[{}] is not in proper int form.", str);
> - LOGGER.error("[{}] not in expected format.", value, e);
> - }
> + try {
> + return Long.parseLong(str) * multiplier;
> + } catch (final NumberFormatException e) {
> + LOGGER.error("[{}] is not in proper int form.", str);
> + LOGGER.error("[{}] not in expected format.", value, e);
> }
> return defaultValue;
> }
>
>
>