[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-dev
Subject:    [jira] [Closed] (LOG4J2-56) Level.toLevel throws IllegalArgumentException instead of returning defau
From:       "John Owen Atala (Closed) (JIRA)" <jira () apache ! org>
Date:       2012-02-03 19:21:55
Message-ID: 251703757.8597.1328296915597.JavaMail.tomcat () hel ! zones ! apache ! org
[Download RAW message or body]


     [ 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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic