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:
Guillaume Smet
2021-04-14 18:36:36 +02:00
parent 25b9a2ce33
commit 6efe428f57

View File

@@ -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;
}
}