Literally the only exception that's possible there is NumberFormatException, but I do agree in principle.
On 28 August 2014 01:56, Remko Popma <[email protected]> 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, <[email protected]> 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 <[email protected]>
