[
https://issues.apache.org/jira/browse/LOG4J2-56?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Ralph Goers resolved LOG4J2-56.
-------------------------------
Resolution: Fixed
Assignee: Ralph Goers
Thanks. I created a unit test to verify the problem and then resolved it using
option b. Please verify and close.
> 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: [email protected]
For additional commands, e-mail: [email protected]