mirror of
https://github.com/jlengrand/github-api.git
synced 2026-03-10 08:21:21 +00:00
Log a warning when we have an unknown enum value
Can be useful to catch values we should add instead of simply ignoring them.
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
package org.kohsuke.github.internal;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* Utils for Enums.
|
||||
*/
|
||||
public final class EnumUtils {
|
||||
|
||||
private static final Logger LOGGER = Logger.getLogger(EnumUtils.class.getName());
|
||||
|
||||
/**
|
||||
* Returns an enum value matching the value if found, null if the value is null and {@code defaultEnum} if the value
|
||||
* cannot be matched to a value of the enum.
|
||||
@@ -30,6 +33,8 @@ public final class EnumUtils {
|
||||
try {
|
||||
return Enum.valueOf(enumClass, value.toUpperCase(Locale.ROOT));
|
||||
} catch (IllegalArgumentException e) {
|
||||
LOGGER.warning("Unknown value " + value + " for enum class " + enumClass.getName() + ", defaulting to "
|
||||
+ defaultEnum.name());
|
||||
return defaultEnum;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user