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

workaround for enums corrupted by ProGuard #1147

Closed
wants to merge 1 commit into from

Conversation

amogilev
Copy link
Contributor

Default ProGuard configuration removes valueOf() and values() from the
processed enum classes. As a result, type.getEnumConstants() == null for
such classes, and NullPointerException was thrown from the constructor
of EnumTypeAdapter.

As an example of the corrupted enum classes, see Predicates.ObjectPredicates
from jersey-guava (up to 2.25.1 so far).
Also see https://www.guardsquare.com/en/proguard/manual/examples#enumerations

No unit tests are provided now, but you can reproduce the exception using
code like this:
import jersey.repackaged.com.google.common.base.Predicates;
...
new Gson().toJson(Predicates.alwaysTrue());

Default ProGuard configuration removes valueOf() and values() from the
processed enum classes. As a result, type.getEnumConstants() == null for
such classes, and NullPointerException was thrown from the constructor
of EnumTypeAdapter.

As an example of the corrupted enum classes, see Predicates.ObjectPredicates
from jersey-guava (up to 2.25.1 so far).
Also see https://www.guardsquare.com/en/proguard/manual/examples#enumerations

No unit tests are provided now, but you can reproduce the exception using
code like this:
  import jersey.repackaged.com.google.common.base.Predicates;
  ...
  new Gson().toJson(Predicates.alwaysTrue());
@Marcono1234
Copy link
Collaborator

Would it maybe be better to throw a descriptive exception? With this proposed change it would fall back to the reflection based approach which is likely not going to help in this situation and might make debugging difficult.

Or is there a use case where you do not want any exception at all and an improperly (de-)serialized enum is better?

@Marcono1234
Copy link
Collaborator

Also similar to #1495 maybe a more reliable solution would be to go through the declared fields and filter by Field.isEnumConstant().

@Marcono1234
Copy link
Collaborator

Looks like this has been superseded by #1495, thank you nonetheless for the pull request!

@Marcono1234 Marcono1234 closed this Aug 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants