Skip to content

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
Contributor

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
Contributor

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
Contributor

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

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.

3 participants