NoSuchFieldException when serializing objects with an enumeration field on Samsung devices running Android 5.0.x
See original GitHub issueStack trace
java.lang.AssertionError: java.lang.NoSuchFieldException: ENUM_CONSTANT_NAME
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter#<init>(808)
at com.google.gson.internal.bind.TypeAdapters$30#create(834)
at com.google.gson.Gson#getAdapter(423)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory#createBoundField(115)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory#getBoundFields(164)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory#create(100)
at com.google.gson.Gson#getAdapter(423)
at com.google.gson.Gson#toJson(661)
at com.google.gson.Gson#toJson(648)
at com.google.gson.Gson#toJson(603)
at com.google.gson.Gson#toJson(583)
at com.myapp.mypackage.MyClass#myMethod()
Crash Descriprion
I can see this crash on Samsung devices running Android 5.0.x only. I’m using gson-2.7 and I’m not usin ProGurad.
The crash occurs when I try to serialize an object of a specific type that contains a field of type enumeration. However, it does not occur sistematically but rather randomly.
As fas as I understand, such an exception cannot be caused by my app’s code. Moreover, by inspecting gson code, I cannot understand why this exception is generated. It seems to me that this should never happen:
for (T constant : classOfT.getEnumConstants()) {
String name = constant.name();
SerializedName annotation = classOfT.getField(name).getAnnotation(SerializedName.class);
...
}
The NoSuchFieldException exception is thrown when the Class.getField(String name)
method is called (line 797)
Any idea on why this exception is thrown? What could be the reason that causes a similar crash?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Developers - NoSuchFieldException when serializing objects with ...
NoSuchFieldException when serializing objects with an enumeration field on Samsung devices running Android 5.0.x.
Read more >java - NoSuchFieldException when field exists - Stack Overflow
I am getting NoSuchFieldException even when using getDeclaredField() , and the "has private access" error even after using setAccessible(true) . Example 1: ...
Read more >Build.VERSION_CODES - Android Developers
VERSION_CODES extends Object ... They are assumed to support different screen densities and sizes. ... Released publicly as Android 5.0 in November 2014....
Read more >Diff - platform/frameworks/base - Google Git
Note: This is set at first run and cannot be changed without * breaking apps that access the provider. diff --git a/core/java/android/provider/CallLog ...
Read more >Gson proguard SerializedName
NoSuchFieldException when serializing objects with an enumeration field on Samsung devices running Android 5.0.x #924.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
this is not a bug in samsungs version of android. i get the same thing on a nexus5x running android 8.1.0. its more lily a pro guard issue. See: https://stackoverflow.com/questions/15543607/assertionerror-in-gson-enumtypeadapter-when-using-proguard-obfuscation
Try method from this article: https://medium.com/@hanru.yeh/gson-will-crash-at-enum-fields-in-custom-class-with-proguard-bbcf5ad1b623 It helped me