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

code/simplification/object optimisation causing NullPointerException #402

Open
remi-sf opened this issue May 3, 2024 · 0 comments
Open

Comments

@remi-sf
Copy link

remi-sf commented May 3, 2024

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.

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.

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:

  • Update the path to the Java 21 JDK in jdk.home for each pom.xml
  • Run the following:
mvn clean package
java -jar proguard-issue/target/proguard-issue-0.0.1-SNAPSHOT.jar

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?

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

1 participant