Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fatal Exception: java.lang.AssertionError: annotation value type != return type #1242

Open
ominfowave opened this issue Jan 31, 2018 · 13 comments
Assignees
Labels
android Issues which are exclusive to Android, and don't occur with a JDK (even if ProGuard / R8 is used)

Comments

@ominfowave
Copy link

Fatal Exception: java.lang.AssertionError: annotation value type != return type
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:649)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Field.getAnnotation(Field.java:242)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldNames(ReflectiveTypeAdapterFactory.java:72)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:159)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:100)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
at com.google.gson.Gson.getAdapter(Gson.java:423)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:853)
at com.google.gson.Gson.fromJson(Gson.java:802)
at com.watchlivetv.onlineradioapp.sync.ZalunuSyncAdapter.parsingServerStation(ZalunuSyncAdapter.java:224)
at com.watchlivetv.onlineradioapp.sync.ZalunuSyncAdapter.performLocalSync(ZalunuSyncAdapter.java:186)
at com.watchlivetv.onlineradioapp.sync.ZalunuSyncAdapter.onPerformSync(ZalunuSyncAdapter.java:176)
at android.content.AbstractThreadedSyncAdapter$SyncThread.run(AbstractThreadedSyncAdapter.java:259)

@inder123
Copy link
Collaborator

inder123 commented May 3, 2018

I see this exception (in Fabric) on Samsung S5 devices running Android OS 5.0, 5.0.1 and 5.0.2

As I look into Android source-code toAnnotationInstance() method for Android 5.0, I see that the exception is thrown here:

645    private static <A extends Annotation> A More ...toAnnotationInstance(Class<?> context, Dex dex,
646            Class<A> annotationClass, EncodedValueReader reader) {
647        int fieldCount = reader.readAnnotation();
648        if (annotationClass != context.getDexCacheType(dex, reader.getAnnotationType())) {
649            throw new AssertionError("annotation value type != return type");
650        }

From http://grepcode.com/file/repo1.maven.org/maven2/org.robolectric/android-all/5.0.0_r2-robolectric-1/libcore/reflect/AnnotationAccess.java#AnnotationAccess.toAnnotationInstance%28java.lang.Class%2Cjava.lang.Class%2Ccom.android.dex.Annotation%29

annotationClass here should be SerializedName.class
I am not sure why context.getDexCacheType doesn't return the same class?

I have seen this problem with a later Gson version. May be this is happening because S5 possibly bundles a older version of Gson in system class path, and hence isn't able to match the two classes?

@inder123
Copy link
Collaborator

inder123 commented May 4, 2018

@swankjesse @JakeWharton Do you guys have any insights on what is causing this?

@swankjesse
Copy link
Collaborator

Good idea. If you have such a device you should be able to detect if there’s a Gson on its system classpath.

@inder123
Copy link
Collaborator

inder123 commented May 4, 2018

@swankjesse How do we detect that Gson is in system classpath?

@swankjesse
Copy link
Collaborator

Run a program with no Gson and call Class.forName() to class load it!

@inder123
Copy link
Collaborator

inder123 commented May 7, 2018

@swankjesse That wont work. In an app, Gson needs to detect if a different system classpath version is present and throw an appropriate error.

@inder123
Copy link
Collaborator

inder123 commented May 7, 2018

@swankjesse Here is a solution which may help.
We should add a version string in Gson. And add it to unexpected stack traces so that we know which version ran into the problem.

@swankjesse
Copy link
Collaborator

My suggestion was intended as a way to detect if this is the root cause and not as something we'd ship.

@inder123
Copy link
Collaborator

inder123 commented Aug 2, 2018

In the stack trace below, Gson is referred to at line 458 which is the current line number for factory.create() call for Gson. This indicates that the Gson instance is coming from the latest version of the Gson jar. For some weird reason, the SerializedName.class annotation is messed up in the dex?

Fatal Exception: java.lang.AssertionError: annotation value type != return type
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:649)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at java.lang.reflect.Field.getAnnotation(Field.java:242)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getFieldNames(ReflectiveTypeAdapterFactory.java:74)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.getBoundFields(ReflectiveTypeAdapterFactory.java:161)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:102)
at com.google.gson.Gson.getAdapter(Gson.java:458)
at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:64)
at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330)
at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313)
at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:736)
at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:169)
at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
at java.lang.reflect.Proxy.invoke(Proxy.java:397)

@elviswoo
Copy link

elviswoo commented Apr 9, 2019

@inder123 Have you found a way to fix this problem? Have you found the root cause of this problem?

@inder123
Copy link
Collaborator

No, I didn't @elviswoo

@bubbleguuum
Copy link

bubbleguuum commented Jul 9, 2019

I've also seen this in my automatted crash reports, where Gson is not involved, on Samsung S5 running Android 5.0:

java.lang.AssertionError: annotation value type != return type
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:649)
at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:641)
at libcore.reflect.AnnotationAccess.getDeclaredAnnotation(AnnotationAccess.java:170)
at libcore.reflect.AnnotationAccess.getAnnotation(AnnotationAccess.java:72)
at java.lang.Class.getAnnotation(Class.java:343)
at androidx.coordinatorlayout.widget.CoordinatorLayout.d(SourceFile:12)
at androidx.coordinatorlayout.widget.CoordinatorLayout.e(SourceFile:5)
at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(SourceFile:1)
at android.view.View.measure(View.java:18543)

@bekabot
Copy link

bekabot commented Nov 4, 2019

I am having the same bug for Samsung Galaxy S5 with Android 5.0

@JakeWharton JakeWharton removed their assignment Dec 15, 2020
@eamonnmcmanus eamonnmcmanus added the android Issues which are exclusive to Android, and don't occur with a JDK (even if ProGuard / R8 is used) label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issues which are exclusive to Android, and don't occur with a JDK (even if ProGuard / R8 is used)
Projects
None yet
Development

No branches or pull requests

8 participants