I have the following statement in my proguard-rules.pro to strip out logging in the production apk:
-assumenosideeffects class android.util.Log { public static boolean isLoggable(java.lang.String, int); public static int v(...); public static int i(...); public static int w(...); public static int d(...); public static int e(...); } This has the effect of removing statements like:
Log.d(TAG, "setup finished"); Now let's consider the following statement:
Log.d(TAG, "setup finished with status " + client.getStatus()); My assumption until now was that this Log.d() statement would be stripped out and therefore that client.getStatus() would never get called.
Specifically, if client happens to be null then my assumption had been that there would be no NullPointerException.
But now I'm not so sure. Perhaps the compiler looks at the above statement more like the following:
int status = client.getStatus(); Log.d(TAG, "setup finished with status " + status); Now the client.getStatus() statement is executed and NullPointerException may result.
What is the actual situation?
Note: I'm actually now using R8 rather than ProGuard.
statusfrom appearing in the logs, even if thestatusis actually fetched. I'm just trying to track down the elusive source of aNullPointerExceptionin my production apk and now I'm starting to consider what I am executing in theseLogstatements, whereas previously I'd assumed that they would never result in aNullPointerExceptionbecause they are stripped out completely.client.getStatus()statement is separated out from theLog.d()statement. Even if theLog.d()statement is removed from the code during preprocessing, this still leaves theclient.getStatus()statement! And it is theclient.getStatus()statement that may be the source of aNullPointerException, not theLog.d()statement per se. Or is it the case that R8/ProGuard will also (automatically) remove theclient.getStatus()statement because its result is never used?