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

java.lang.VerifyError #2310

Closed
ylk2534246654 opened this issue Feb 5, 2023 · 11 comments
Closed

java.lang.VerifyError #2310

ylk2534246654 opened this issue Feb 5, 2023 · 11 comments
Labels

Comments

@ylk2534246654
Copy link

Gson version

2.10.1

Java / Android version

Android 4.0.3

Description

Error after updating from 2.9.1 to 2.10.1

Exception stack trace

W/System.err: Caused by: java.lang.VerifyError: com/google/gson/internal/reflect/ReflectionHelper
W/System.err:     at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:122)
W/System.err:     at com.google.gson.Gson.getAdapter(Gson.java:556)
W/System.err:     at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
W/System.err:     at com.google.gson.Gson.getAdapter(Gson.java:556)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:1226)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:1137)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:1047)
W/System.err:     at com.google.gson.Gson.fromJson(Gson.java:1014)
@Marcono1234
Copy link
Collaborator

Marcono1234 commented Feb 5, 2023

Does this occur on an actual Android device? The comments on #1353 suggest that this might (in the past) have been caused by Google Play Pre-Launch and does not occur on actual devices.

Also Android 4.0.3 is somewhat old; I think there are a few issue reports here where users encountered problems because some vendors included themselves Gson in their Android version, which caused conflicts, see #255. Though that might have only occurred for even older Android versions.

For which device does this occur? Does this occur only for one device or also for other ones (with newer Android versions)? Is this the complete exception stack trace or is there more information about why the verifier rejected the class?

@ylk2534246654
Copy link
Author

The Android simulator is used.

This problem only occurs in Gson version 2.10.

The problem cannot be found in Android 5.0 and above.

@Marcono1234
Copy link
Collaborator

Thanks for the answer!

The Android simulator is used.

Do you mean an Android Emulator started from the IDE (e.g. Android Studio)? Has this issue also appeared on a real device? Is there more information in the exception stack trace why the VerifyError occurred?

@ylk2534246654
Copy link
Author

        TypeToken<List<StringBean>> typeToken = new TypeToken<>() {};
        return gson.fromJson(databaseValue,typeToken.getType());
E/AndroidRuntime: FATAL EXCEPTION: main
    java.lang.VerifyError: com/google/gson/internal/reflect/ReflectionHelper
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:122)
        at com.google.gson.Gson.getAdapter(Gson.java:556)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
        at com.google.gson.Gson.getAdapter(Gson.java:556)
        at com.google.gson.Gson.fromJson(Gson.java:1226)
        at com.google.gson.Gson.fromJson(Gson.java:1137)
        at com.google.gson.Gson.fromJson(Gson.java:1047)
        at com.google.gson.Gson.fromJson(Gson.java:1014)

Yes, I am using the Android emulator on Android Studio, as I do not have a real device with Android 4.0.3 version, I cannot test it, and in the stack trace I can only provide these useful information.

@AhmadullahSaikat
Copy link

AhmadullahSaikat commented May 13, 2023

I got this problem below Marshmallow devices.
Android 17, 18, 19, 21 & 22 versions.

For this upgrade Android 21 & 22 have errors on: Collections2.filter & ExoPlayer.Builder(this).build()

But: com.google.code.gson:gson:2.9.1, this problem not occurred.

@Marcono1234
Copy link
Collaborator

I got this problem below Marshmallow devices.
Android 17, 18, 19, 21 & 22 versions.

Same question as above, do you experience this on real physical devices or only on emulators?

have errors on: Collections2.filter & ExoPlayer.Builder(this).build()

What do you mean by that? Are these classes calling Gson methods and this is where the VerifyError occurs, or does the VerifyError occur for those classes / methods and is actually unrelated to Gson?

@vishalsingh2972
Copy link

@ylk2534246654 can you please review PR #2398

@adbenitez
Copy link

adbenitez commented Jun 30, 2023

@Marcono1234 this issue is happening on real Android 4 devices of Delta Chat users

UPDATE: I switched to version 2.9.1 and it works fine, so the issue is in 2.10.1

@Marcono1234
Copy link
Collaborator

Thanks a lot! The full crash log of deltachat/deltachat-android#2610 contains the following interesting lines:

W/dalvikvm( 6523): VFY: unable to find class referenced in signature (Ljava/lang/ReflectiveOperationException;)
W/dalvikvm( 6523): VFY: unable to find class referenced in signature (Ljava/lang/ReflectiveOperationException;)
W/dalvikvm( 6523): VFY: unable to find class referenced in signature (Ljava/lang/ReflectiveOperationException;)
W/dalvikvm( 6523): VFY: Ljava/lang/Object; is not instance of Ljava/lang/Throwable;
W/dalvikvm( 6523): VFY: bad arg 2 (into Ljava/lang/Throwable;)
W/dalvikvm( 6523): VFY:  rejecting call to Ljava/lang/RuntimeException;.<init> (Ljava/lang/String;Ljava/lang/Throwable;)V
W/dalvikvm( 6523): VFY:  rejecting opcode 0x70 at 0x0004
W/dalvikvm( 6523): VFY:  rejected Lcom/google/gson/internal/reflect/ReflectionHelper;.createExceptionForRecordReflectionException (Ljava/lang/ReflectiveOperationException;)Ljava/lang/RuntimeException;
W/dalvikvm( 6523): Verifier rejected class Lcom/google/gson/internal/reflect/ReflectionHelper;

According to the documentation java.lang.ReflectiveOperationException was only added for Android API level 19 (Android 4.4), so that might explain this error then. (Have not tested this myself yet though.)

To my knowledge no official minimum Android API level has been documented for Gson so far; I have created #2429 for that now. I guess for this specific issue with ReflectiveOperationException it would be possibly to adjust the Gson code to remove usage of it, the code would probably only become slightly more verbose.
Though I don't know at the moment if there might be other code which is incompatible with those Android versions as well.

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Jul 6, 2023

It was decided in #2429 that future Gson versions require at least Android API level 21 (Android 5), because nowadays only a small number of devices is still using older versions. This is also consistent with the minimum Android API level specified by other popular libraries such as OkHttp or Retrofit.

Gson 2.10.1 and older should support Android API level 19 as minimum (newer Gson versions might work with Android API level 19 as well, but it is not guaranteed).

The code which is causing this VerifyError was introduced in Gson 2.10, so most likely any older Gson version will not encounter this issue. However, as mentioned in #2429 (comment) other Gson code is using features which were also added for API level 19. So I assume we cannot guarantee that you won't run into other issues with API level < 19 even for older Gson versions.

So I think this VerifyError will not be fixed, and unfortunately your only choice might be to keep using older Gson versions in case you want to support API level < 19 (respectively < 21) for your app. @eamonnmcmanus, we can close this issue here then, right?

However, if you experience this VerifyError for an API level which should be supported by Gson according to the README, then please let us know here or create a new issue.

@eamonnmcmanus
Copy link
Member

Yes, I think we can close this issue. If you need to support very old Android versions then you must use an old Gson version.

@eamonnmcmanus eamonnmcmanus closed this as not planned Won't fix, can't repro, duplicate, stale Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants
@eamonnmcmanus @Marcono1234 @AhmadullahSaikat @adbenitez @ylk2534246654 @vishalsingh2972 and others