Skip to content

Commit 0513b1d

Browse files
committed
Fix crashes in some enum operations
These are notable in the latest Android versions.
1 parent 8aa7816 commit 0513b1d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

library/src/main/java/me/proxer/library/api/DelimitedEnumSetAdapterFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ public Set<T> fromJson(final JsonReader reader) throws IOException {
7777

7878
for (final String part : parts) {
7979
for (final Field field : enumType.getFields()) {
80-
if (field.getAnnotation(Json.class).name().equals(part)) {
80+
Json annotation = field.getAnnotation(Json.class);
81+
82+
if (annotation != null && annotation.name().equalsIgnoreCase(part)) {
8183
result.add(Enum.valueOf(enumType, field.getName()));
8284

8385
break;

library/src/main/java/me/proxer/library/util/ProxerUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public String getApiEnumName(final Enum<?> it) {
4040
@Nullable
4141
public <T extends Enum<T>> T toApiEnum(final Class<T> type, final String value) {
4242
for (final Field field : type.getFields()) {
43-
if (field.getAnnotation(Json.class).name().equalsIgnoreCase(value)) {
43+
Json annotation = field.getAnnotation(Json.class);
44+
45+
if (annotation != null && annotation.name().equalsIgnoreCase(value)) {
4446
return Enum.valueOf(type, field.getName());
4547
}
4648
}

0 commit comments

Comments
 (0)