Debian Codegraph @

framework/tests/all-systems/TypeVarAndArrayRefinement.java

raw
1 class TypeVarAndArrayRefinement {
2
3 private <T extends Enum<T>> T getEnumValue(Class<T> enumType, String name) {
4 T[] constants = enumType.getEnumConstants();
5 if (constants == null) {
6 throw new IllegalArgumentException(enumType.getName() + " is not an enum type");
7 }
8 // previously the constants method was considered nullable mainly because it was an invalid
9 // type because when lubbing type variables we didn't copy the declared types on the bounds
10 // over to the lub
11 for (T constant : constants) {
12 if (constant.name().equalsIgnoreCase(name.replace('-', '_'))) {
13 return constant;
14 }
15 }
16 // same error that's thrown by Enum.valueOf()
17 throw new IllegalArgumentException(
18 "No enum constant " + enumType.getCanonicalName() + "." + name);
19 }
20 }