Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
0.1
-
None
-
None
-
Java 6
Description
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
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 defaultLevel;
I prefer b) because it saves the try-catch context and the for is nearly the same that the valueOf should do.