logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Owen Atala (Closed) (JIRA)" <j...@apache.org>
Subject [jira] [Closed] (LOG4J2-56) Level.toLevel throws IllegalArgumentException instead of returning default Level
Date Fri, 03 Feb 2012 19:21:55 GMT

     [ https://issues.apache.org/jira/browse/LOG4J2-56?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

John Owen Atala closed LOG4J2-56.
---------------------------------


Verified at r1240306
                
> Level.toLevel throws IllegalArgumentException instead of returning default Level
> --------------------------------------------------------------------------------
>
>                 Key: LOG4J2-56
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-56
>             Project: Log4j 2
>          Issue Type: Bug
>          Components: API
>    Affects Versions: 0.1
>         Environment: Java 6
>            Reporter: John Owen Atala
>            Assignee: Ralph Goers
>            Priority: Minor
>   Original Estimate: 10m
>  Remaining Estimate: 10m
>
> org.apache.logging.log4j.Level.toLevel(String, Level) ( Level.java line 100) uses enum
static method valueOf(String) which throws IllegalArgumentException instead of returning null
when enum const doesnt exists. This makes the methods Level.toLevel throw the exception instead
of return default value.
> Solution:
> You can:
> a) sorround it with a try-catch statement, like:
>         try {
> 			return valueOf(sArg);
> 		} catch (Exception e) {
> 			//exception doesnt matter
> 			return defaultLevel;
> 		}
> b) translate manually de String to a enum constant, like:
>         for (Level level : values()) {
> 			if (level.name().equals(sArg)) {
> 				return level;
> 			}
> 		}
>         return defaultLevel;
> I prefer b) because it saves the try-catch context and the for is nearly the same that
the valueOf should do.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-dev-help@logging.apache.org


Mime
View raw message