predictNullPointerExceptions is enabled when not optimizing aggressively
After upgrading from 7.2 to 7.4.1, we notice the generation of throw new NullPointerException() for statements that use a field injected by Spring DI.
Commit https://github.com/Guardsquare/proguard/commit/3445fa02d6263568fe495b4b23688820f09d7203 shows how the predictNullPointerExceptions feature is introduced. Apparently, predictNullPointerExceptions is set to true when not optimizing aggressively, and is omitted when you do optimize aggressively.
This seems counterintuitive. We don't want aggresive optimization, but these incorrect throw new NullPointerException() statements make our application crash.
Our only way forward now is to don't optimize anything with -dontoptimize? 🤷
Thank you for reporting this.
You should be able to work around this by disabling optimization for the affected method(s), i.e.:
-keep,includecode class <affectedclass> {
<affectedmethod>;
}
Thank you for your answer. As we have a very large application, this happens in many hundreds of places. This workaround would require a lot of time to implement, and developers would have to think about ProGuard optimization when they write code.