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

Proguard rules for 2.8.8? #1946

Closed
slowcar opened this issue Aug 31, 2021 · 4 comments
Closed

Proguard rules for 2.8.8? #1946

slowcar opened this issue Aug 31, 2021 · 4 comments

Comments

@slowcar
Copy link

slowcar commented Aug 31, 2021

Hi,

i have an issue with our app, and it looks like the update of the gson library from 2.8.7 to 2.8.8 is the culprit.
I suspected proguard and updated the rules from https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg which did not resolve the issues. However, the rules are older than the 2.8.8 release, so maybe the have to be updated?

Looking at the stacktraces it seems to be related to enum:
Caused by: java.lang.ClassCastException: com.microsoft.identity.client.configuration.AccountMode[] cannot be cast to java.lang.Enum
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.(SourceFile:7)

Checking the release notes i see that 2.8.8 changed this class:
https://github.com/google/gson/releases/tag/gson-parent-2.8.8
EnumTypeAdapter now works better when ProGuard has obfuscated enum fields (#1495).

Now i am unsure what exactly causes the issue, as it only occurs when the apk is wrapped with mobile iron. but as downgrading to json 2.8.7 fixed the issue i decided to write this post anyway.

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Aug 31, 2021

(SourceFile:7)

That looks rather weird. Was the exception maybe cut off when you pasted it here, or is ProGuard modifying the Gson JAR? At line 7 there is no Java code.
I assume your AccountMode class is an enum (is that correct?), though the question is then how an array of enum constants ended up in EnumTypeAdapter. The check in TypeAdapters should not match arrays:

if (!Enum.class.isAssignableFrom(rawType) || rawType == Enum.class) {

And #1495 only changed the way enum constant fields are detected, using Java's / Android's Field.isEnumConstant().

So the only reasons for this I can think of are:

  • Something corrupted / created malformed bytecode for your AccountMode enum class
  • Somehow the TypeToken Gson was using did not match the type which was (de-)serialized

Maybe the maintainers have more ideas what could have went wrong.

Though could you please provide a more complete stack trace (containing at least all of the lines belonging to Gson)?


Note that I am not maintainer of this project.

@slowcar
Copy link
Author

slowcar commented Sep 24, 2021

Sorry for the delay, i was away on holiday.

Here is a complete stacktrace:
java.lang.IllegalArgumentException: Error while processing configuration
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:16)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:3)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfiguration(SourceFile:2)
at com.microsoft.identity.client.PublicClientApplication$4.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.ClassCastException: com.microsoft.identity.client.configuration.AccountMode[] cannot be cast to java.lang.Enum
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.(SourceFile:7)
at com.google.gson.internal.bind.TypeAdapters$30.create(SourceFile:5)
at com.google.gson.Gson.n(SourceFile:9)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(SourceFile:4)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.d(SourceFile:15)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(SourceFile:4)
at com.google.gson.Gson.n(SourceFile:9)
at com.google.gson.Gson.i(SourceFile:5)
at com.google.gson.Gson.k(SourceFile:2)
at com.google.gson.Gson.m(SourceFile:2)
at com.google.gson.Gson.l(SourceFile:1)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:13)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:3)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfiguration(SourceFile:2)
at com.microsoft.identity.client.PublicClientApplication$4.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:919)
2021-09-24 15:32:29.532 30756-30796/? E/FPExceptionHandler: Error while processing configuration
java.lang.IllegalArgumentException: Error while processing configuration
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:16)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:3)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfiguration(SourceFile:2)
at com.microsoft.identity.client.PublicClientApplication$4.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:919)
Caused by: java.lang.ClassCastException: com.microsoft.identity.client.configuration.AccountMode[] cannot be cast to java.lang.Enum
at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter.(SourceFile:7)
at com.google.gson.internal.bind.TypeAdapters$30.create(SourceFile:5)
at com.google.gson.Gson.n(SourceFile:9)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.a(SourceFile:4)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.d(SourceFile:15)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(SourceFile:4)
at com.google.gson.Gson.n(SourceFile:9)
at com.google.gson.Gson.i(SourceFile:5)
at com.google.gson.Gson.k(SourceFile:2)
at com.google.gson.Gson.m(SourceFile:2)
at com.google.gson.Gson.l(SourceFile:1)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:13)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.loadConfiguration(SourceFile:3)
at com.microsoft.identity.client.PublicClientApplicationConfigurationFactory.initializeConfiguration(SourceFile:2)
at com.microsoft.identity.client.PublicClientApplication$4.run(SourceFile:2)
at java.lang.Thread.run(Thread.java:919)

The file in question (from Microsoft MSAL library) is quite simple:

package com.microsoft.identity.client.configuration;

public enum AccountMode {
    SINGLE,
    MULTIPLE
}

@Marcono1234
Copy link
Collaborator

Thanks! Would it be possible to disable ProGuard processing for the Gson library classes? Maybe ProGuard somehow changed Gson's implementation by accident. Additionally these obfuscated stack traces make it difficult to tell where exactly the exception occurred in Gson.

Using ProGuard for user classes is something which this library apparently wants to support (at least to some extend), but I am not sure if the maintainers want to support using ProGuard on the Gson classes itself, because it makes debugging like in this case harder.

@slowcar
Copy link
Author

slowcar commented Oct 8, 2021

closing this issue, as it seems to be related to mobile iron wrapping, and us discontinueing using this wrapper

@slowcar slowcar closed this as completed Oct 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants