You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My project uses Gson to deserialise a simple JSON file to an object. To achieve this, the code uses several objects containing fields annotated with @com.google.gson.annotations.SerializedName. Those fields then don't need to be initialised or set within the code.
When I run the application, reading the response JSON and deserialising it to an object, I expect to be able to access every field in the object. However, Proguard modifies several methods to throw null at the end, which naturally causes a crash when I try to e.g. print out the deserialised object.
java -jar proguard-issue/target/proguard-issue-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NullPointerException: Cannot throw exception because "null" is null
at uk.co.screamingfrog.d.toString(Unknown Source)
at java.base/java.lang.String.valueOf(String.java:4461)
at uk.co.screamingfrog.e.toString(Unknown Source)
at java.base/java.lang.String.valueOf(String.java:4461)
at uk.co.screamingfrog.Main.main(Unknown Source)
This issue goes away if you add -optimizations !code/simplification/object to the Proguard config.
I'm experiencing unexpected behaviour running Proguard 7.4.0.
My project uses Gson to deserialise a simple JSON file to an object. To achieve this, the code uses several objects containing fields annotated with
@com.google.gson.annotations.SerializedName
. Those fields then don't need to be initialised or set within the code.I have referred to an example proguard config from the Gson repo: https://github.com/google/gson/blob/570d91194e223132982d56b6fa499af15fd7b1ea/examples/android-proguard-example/proguard.cfg
When I run the application, reading the response JSON and deserialising it to an object, I expect to be able to access every field in the object. However, Proguard modifies several methods to
throw null
at the end, which naturally causes a crash when I try to e.g. print out the deserialised object.This issue goes away if you add
-optimizations !code/simplification/object
to the Proguard config.My example project:
proguard_issue.zip
The result when I run
mvn package
on my machine:proguard-issue-0.0.1-SNAPSHOT.jar.zip
To reproduce:
Is this expected behaviour for this optimisation? If so, is there a way to remove the optimisation only for fields annotated as in this example?
The text was updated successfully, but these errors were encountered: